//---------------------------------------------------------------------- //---------------------------------------------------------------------- include "hwreg-p16f628.h" // 16f628 config // enable internal oscillator FOSC2,FOSC1,FOSC0 = 100 // disable watchdog WDT = 0 // enable power up timer PWRTE = 0 // use MCLR as RA5 MCLRE = 0 // disable brown-out detect BODEN = 0 // low voltage prog disabled LVP = 0 // data memory not protected CPD = 1 // code memory not protected CP1,CP0,CP1,CP0 = 1111 // // see section 14.1 of PIC16F26X ref manual // microchip document name 40300b.pdf pragma cpu_config 0x3F10 include "strlib.bas" include "lcdlib.bas" // 16 byte fifo (+3 bytes for fifo control) ubyte USART_input_fifo[19] ubyte USART_output_fifo[19] // NOTE: // USART_input_fifo and USART_output_fifo // MUST BE DEFINED // before usart_int_lib.bas is included include "usart_int_lib.bas" //---------------------------------------------------------------------- //---------------------------------------------------------------------- proc main() ubyte j, k int ch char char_to_send // set PORTA to digital I/O instead of analog CMCON = 7 TRISA = TRISA & ~1 fifo_init(&USART_input_fifo, 16) fifo_init(&USART_output_fifo, 16) USART_init() LCD_init() USART_enable_TX_interrupt() USART_enable_RX_interrupt() INTCON = INTCON | (1 << PEIE) // 0x41 == 'A' char_to_send = 0x41 LCD_set_pos(0, 0) LCD_write_str_code("hello world") LCD_set_pos(0, 1) USART_send_str_code("hello world") while 1 do PORTA = PORTA & ~1 for j=0 while j<100 step j+=1 do delay_m4clk 250 done PORTA = PORTA | 1 USART_send(char_to_send) for k=0 while k<3 step k+=1 do for j=0 while j<100 step j+=1 do delay_m4clk 250 done done ch = USART_read() if ch >= 0 then char_to_send = ch if ch == 10 || ch == 13 then LCD_set_pos(0, 0) else LCD_write_char(ch) endif endif done endproc //---------------------------------------------------------------------- //---------------------------------------------------------------------- proc intserv() USART_service_RX() USART_service_TX() endproc