Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

108 lines (90 sloc) 2.414 kB
/* ----------------------------------------------------------------------- */
/* Template source file generated by piklab */
#include <pic16f877.h>
//#include <stdio.h>
/* ----------------------------------------------------------------------- */
/* Configuration bits: adapt to your setup and needs */
typedef unsigned int word;
word at 0x2007 CONFIG = _XT_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_ON & _LVP_ON & _CPD_OFF & _WRT_ENABLE_ON & _DEBUG_ON & _CP_OFF;
void delay(unsigned count) {
while (count--) {
continue;
}
}
void adc_setup() {
TRISA = 0x03; // signal input on pA0 and pA1
ADFM = 0; // left justifed
PCFG0 = 0; // pA0..3 analogue with vdd/vss ref
PCFG1 = 0;
PCFG2 = 1;
PCFG3 = 0;
ADON = 1;
ADCS0 = 1; // f = 8tosc. 5Mhz max
ADCS1 = 0;
CHS2 = 0;
ADIE = 1;
}
void serial_setup_19200() {
// Configure UART serial transmit
SPBRG = 12; // 4MHz = > 19200 baud
BRGH = 1;
SYNC = 0;
SPEN = 1;
TXIE = 1;
// enable transmission
TXEN = 1;
GIE = 1;
PEIE = 1;
}
#define RING_SZ (16)
char txring[RING_SZ];
unsigned char txring_in = 0;
unsigned char txring_out = 0;
void ad_aquire( unsigned char chan ) {
CHS0 = (chan & 0x01);
CHS1 = (chan & 0x02) ? 1 : 0;
GO = 1;
}
#define AD_INPUTS (2)
unsigned char ad_result[2];
void ad_monitor() {
CHS0 = 0;
CHS1 = 0;
GO = 1;
// let the isr push the next one out
}
void intr() interrupt 0 {
if(TXIF) { // serial interrupt
if( txring_out != txring_in ) {
txring_out = (txring_out + 1) & (RING_SZ-1);
TXREG = txring[txring_out];
}
}
if (ADIF) {
ADIF = 0;
ad_result[CHS0] = ADRESH;
CHS0 = !CHS0;
GO = 1;
}
}
void print(char* p) { unsigned char c; while(c = *p) { unsigned char txring_next = (txring_in + 1) & (RING_SZ-1);
if (txring_next != txring_out) {
txring[txring_next] = c;
txring_in = txring_next;
intr(); // call here to prime if empty tx buffer
p++;
}
}
}
// ----------------------------------------------------------------------------
unsigned char ad[3] = { '1','4','\0' };
void main(void) {
TRISB = 0;
adc_setup();
serial_setup_19200();
ad_monitor();
while (1) {
print(" Hello World\n");
print(ad);
}
}
Jump to Line
Something went wrong with that request. Please try again.