You are on page 1of 2

//#include <lcd.c> //#include <kbd.c> #include "main.h" #include "flex_lcd.

c" //#priority INT_EXT //uu tien ngat ngoai #define LCD_DB4 PIN_D4 #define LCD_DB5 PIN_D5 #define LCD_DB6 PIN_D6 #define LCD_DB7 PIN_D7 #define LCD_E PIN_C6 #define LCD_RS PIN_C4 #define LCD_RW PIN_C5 #priority INT_EXT //int16 count; Signed int16 count1, count; int1 dir; int adc,dv,ht,hc,hn,i,j,t; #int_EXT void EXT_isr(void) { //restart_wdt(); dir=input(pin_b1); if (dir==1) { count=count+1; } else { count=count-1; } //output_bit(pin_c4,dir); } void tach(int16 x) { dv=x%10; hc=x/10; hc=hc%10; ht=x/100; ht=ht%10; hn=x/1000; hn=hn%10; dv=dv+0x30; hc=hc+0x30; ht=ht+0x30; hn=hn+0x30; } void main() { setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1);

setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by

the PICWizard //Setup_Oscillator parameter not selected from Intr Oscillator Config tab set_tris_d(0); set_tris_c(0); set_tris_b(0b11111111); EXT_INT_EDGE(H_TO_L); //Ngat ngoai khi co suon xuong // enable_interrupts(INT_RB); //Cho phep ngat RB4:RB7 enable_interrupts(INT_EXT);//Cho phep ngat ngoai INT0 enable_interrupts(GLOBAL); //Cho phep ngat // lcd_init(); //kbd_init(); count=0; // TODO: USER CODE!! delay_ms(50); lcd_init(); //khoi dong LCD delay_ms(500); while(1) { if((count<0)) { count1=0-count; tach((int16)count1); lcd_gotoxy(1,1); printf(LCD_putc,"Encoder test program"); lcd_gotoxy(1,2); //printf(LCD_putc,"Init OK"); printf(LCD_putc,"T="); printf(LCD_putc,"-"); LCD_putc(hn);LCD_putc(ht);LCD_putc(hc); LCD_putc(dv); } else { tach((int16)count); lcd_gotoxy(1,1); printf(LCD_putc,"Encoder test program"); lcd_gotoxy(1,2); //printf(LCD_putc,"Init OK"); printf(LCD_putc,"T="); printf(LCD_putc,"+"); LCD_putc(hn);LCD_putc(ht);LCD_putc(hc); LCD_putc(dv); } } }

You might also like