/* * File: main.c * Author: * * Created on 2014/07/05, 13:54 */ #define _XTAL_FREQ 8000000 #pragma config FOSC = INTOSCIO #pragma config WDTE = OFF #pragma config PWRTE = OFF #pragma config CP = OFF #pragma config LVP = OFF #include #include #include #include #include #include struct SND_BUF { UCHAR8 buf[10]; UCHAR8 cnt; UCHAR8 pos; }; struct SND_BUF snd_buf; void uartinit() { memset( &snd_buf, 0x00, sizeof(snd_buf)); #if 0 // 9600bps = 8000000 / (16 * (51 + 1)) BRGH = 1; SPBRG = 51; #else // 600bps = 8000000 / (64 * (207 + 1)) BRGH = 0; SPBRG = 207; #endif SYNC = 0; CREN = 1; RCIF = 0; RCIE = 1; RX9 = 0; TXEN = 1; TXIF = 0; TXIE = 0; TX9 = 0; SPEN = 1; //RCIE = 1; //TXIE = 0; //RCREG = RCREG; TRISB2 = 1; TRISB5 = 0; } void snd_test(void) { snd_buf.buf[0] = 0x01; snd_buf.buf[1] = 0x02; snd_buf.buf[2] = 0x03; snd_buf.buf[3] = 0x04; snd_buf.buf[4] = 0x05; snd_buf.buf[5] = 0x06; snd_buf.buf[6] = 0x07; snd_buf.buf[7] = 0x08; snd_buf.buf[8] = 0x09; snd_buf.buf[9] = 0x0a; snd_buf.pos = 0; snd_buf.cnt = 10; TXIE = 1; } void snd() { TXIF = 0; if(snd_buf.pos < snd_buf.cnt) { TXREG = snd_buf.buf[snd_buf.pos]; ++snd_buf.pos; } else { TXIE = 0; memset( &snd_buf, 0x00, sizeof(snd_buf)); } } void interrupt int_all(void) { di(); if(RCIF) { RCIF = 0; UCHAR8 c = RCREG; PORTB = c; if(!snd_buf.cnt) { snd_test(); } } if(TXIF) { snd(); } ei(); } int main(int argc, char** argv) { di(); OSCCON = 0x70; TRISA = 0x00; TRISB = 0x00; uartinit(); GIE = 1; PEIE = 1; ei(); while(1) { } return (EXIT_SUCCESS); }