#include #include "sci.h" #include "delay.h" #include "lcd.h" #define psw1 RB0 //Reset #define psw2 RB3 //Transmit char #define set_speed ( PORTB >> 4) & 0b00000011 //dipsw 3-4 read #define set_echo RB6 //dipsw 1 #define set_mode RB7 //dipsw 2 __CONFIG(0x3F50); char senddata =0;// Transmit data Flag "1" is Send on "0" is void char lcd_loccnt=0x00;//LCD location counter void lcd_disp(char data) { // sci_PutByte('c'); if ((( data >=0 ) && ( data <= 11 )) || (( data >=14) && ( data <= 0x1F))) return; switch ( data ){ case 12 : //clear lcd_clear(); lcd_loccnt =0; break; case 13 : //return command if (lcd_loccnt <= 0x10) lcd_loccnt = 0x40; else if (lcd_loccnt <= 0x50) lcd_loccnt = 0x00; break; default : lcd_putch(data); lcd_loccnt++; break; } if (lcd_loccnt == 0x10) lcd_loccnt = 0x40; if (lcd_loccnt == 0x50) lcd_loccnt = 0x00; lcd_goto(lcd_loccnt); } //#pragma interrupt_level 1 void interrupt tmr0( void ) { if (!psw1) asm("goto 0");//reset if (!psw2) { sci_PutByte(13);//return code while(!psw2); } if ( senddata !=0 ) { sci_PutByte(senddata); senddata =0; } TMR0 = 128 ;//interrupt timer T0IF =0; } //------------------main main() { // Register static int speed = 19200; static char echo_flag; // Port initalize // 76543210 TRISA = 0b00110000; //all port is intput TRISB = 0b11111011; //RB1 USART RXinput the others output PORTA = 0b00000000; //Port Initalize PORTB = 0b00000000; //Port Initalize CMCON = 0x07; //16F627/8 spcial function reg (RAx is port) //timer setting OPTION = 0b00000000; // prescale 2 RBPU= EN GIE = 0;//Int off T0IE = 0;//timer interrupt is off TMR0 = 128;//interrupt timer counter set GIE = 1;//Global interrupt Enable PEIE = 1;//Peripheral interrupt Enable //LCD init lcd_init(); //lcd initalize lcd_clear(); //lcd clear if ( !set_mode ) //set_mode =0 is Custom setting { switch (set_speed){ case 3: speed =2400; lcd_puts("24"); break; case 2: speed =4800; lcd_puts("48"); break; case 1: speed =9600; lcd_puts("96"); break; default : lcd_puts("192"); break; } lcd_puts("00"); //(saving memory) echo_flag = set_echo; if ( echo_flag ) lcd_puts(" EC OFF"); else lcd_puts(" EC ON"); lcd_goto(0x40);//next line lcd_loccnt =0x40;//next line counter } sci_Init(speed ,SCI_EIGHT);// Baud set and Bit set while(!psw1);// button release check T0IE = 1;//timer interrupt on while(1) { char data= sci_GetByte();//RS232C Recive lcd_disp(data); //lcd display recive data if ( !echo_flag ) senddata = data;//echo on if dipsw4 =0 if (sci_CheckOERR()) { //sci error while (!TRMT); CREN=0; senddata='?' ; //RS232C out if sci error CREN=1; } } }