hi all!
I'm new, I have projects using PIC16F877A LCD display reads pulse ecoder using external interrupt RB0. it was running but not visible when communicating with the PC when using "printf CCS"below the source ....
"sory I do not know up core"
please check and comments
Thank!
#include <16F877A.h>
#FUSES HS
#use delay(clock=20000000)
#include <LCD_TM.c>
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8 )
int period = 0,state_old = 0, state = 0, cal = 0, start = 0,relay1 = 0, relay2 = 0;
long dem = 0, rpm = 0, xung = 0;
#int_RB
void RB_isr(void)
{
state = input_b() & 0xF0;
state_old = state;
if(!(state == 0xF0)){
delay_ms(20);
state = input_b() & 0xF0;
if(state == state_old){
switch(state){
case 0xD0:
lcd_gotoxy(1,1);
printf(lcd_putc," ");
lcd_gotoxy(2,1);
printf(lcd_putc,"START ...");
delay_ms(2);
lcd_gotoxy(1,2);
printf(lcd_putc," ");
delay_ms(5);
lcd_gotoxy(1,2);
printf(lcd_putc, "TOC DO: ");
delay_ms(5);
lcd_gotoxy(14,2);
printf(lcd_putc, "RPM");
start = 1;
break;
case 0x70:
if(start==1){
lcd_gotoxy(1,1);
printf(lcd_putc," ");
delay_ms(5);
lcd_gotoxy(1,2);
printf(lcd_putc," ");
delay_ms(5);
lcd_gotoxy(1,1);
printf(lcd_putc,"Stop ");
start = 0;
delay_ms(15);
}
break;
case 0xE0:
relay1++;
relay1 = relay1 % 2;
if(relay1 == 0){
output_high(PIN_D0);
output_high(PIN_E0);
}
if(relay1 == 1){
output_low(PIN_D0);
output_low(PIN_E0);
}
break;
case 0xB0:
relay2++;
relay2 = relay2 % 2;
if(relay2 == 0){
output_high(PIN_C2);
output_high(PIN_E2);
}
if(relay2 == 1){
output_low(PIN_C2);
output_low(PIN_E2);
}
break;
}
}
}
}
#int_EXT
void EXT_isr(void)
{
dem++;
}
#int_TIMER1
void TIMER1_isr(void)
{
period++;
if(period == 5){
xung = dem;
cal = 1;
dem = 0;
period = 0;
}
}
void main()
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
enable_interrupts(INT_RB);
enable_interrupts(INT_EXT);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
set_tris_b(0xF0);
set_tris_d(0x00);
set_tris_c(0x00);
set_tris_e(0x02);
start = 0;
relay1 = 0;
relay2 = 0;
output_low(PIN_D0);
output_low(PIN_C2);
output_low(PIN_E2);
output_low(PIN_E0);
lcd_init();
lcd_gotoxy(2,1);
printf(lcd_putc,"mach do toc do");
lcd_gotoxy(1,2);
printf(lcd_putc,"H.LONG ");
delay_ms(100);
while(TRUE){
while(start){
//output_high(PIN_E2);
if (cal==1){
rpm = (long)(xung)*300/208;
//rpm = xung*3/104;
xung = 0;
lcd_gotoxy(8,2);
printf(lcd_putc, " ");
lcd_gotoxy(9,2);
printf(lcd_putc, "%lu", rpm);
printf("rpm = (long)(xung)*300/208"); //??????????????????
cal = 0;
}
}
}
}