#include <main.h>
#include <on_off.h>
#include <lcd4bit.c>
#include <stdlib.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz FOR PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES NOBROWNOUT //No brownout reset
#FUSES IESO //Internal External SWITCH Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used FOR I/O
#FUSES NODEBUG //No Debug mode FOR ICD
#FUSES NOWRT //Program memory not write protected
#FUSES BORV40 //Brownout reset at 4.0V
#use Fast_IO( B )
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define ccp1 PIN_C2
#define ccp2 PIN_C1
#define en PIN_C4
//UNSIGNED int8 ctimer=0;
float tocdo=0, tocdodat;
float xung=0, xungmoi = 0,xungcu =0 ;
float dem = 0, w=0;
void ngatkenhA();
void NGAT_TIMER1();
float xung21(FLOAT);
#INT_TIMER1
void NGAT_TIMER1()
{
IF(dem >= 4)
{
disable_interrupts (INT_EXT) ;
setup_timer_1 (T1_DISABLED) ;
tocdo = 3.45 * xungmoi;
xungmoi = 0;
set_timer1 (15535) ;
setup_timer_1 (T1_INTERNAL|T1_DIV_BY_1) ;
enable_interrupts (INT_EXT) ;
dem = 0;
}
dem = dem + 1;
w = tocdo;
}
#INT_EXT
void ngatkenhA(VOID)
{
IF (!input (PIN_B0))
{
xungmoi = xungmoi + 1;
}
}
void main()
{
char string[32];
gets(string);
tocdodat = 120;
lcd_init();
set_tris_b(0b00000001);
set_tris_c(0b10000000);
set_tris_d(0x00);
output_d(0x00);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
set_timer1(15535);
enable_interrupts(INT_TIMER1);// ngat timer 1
enable_interrupts(INT_EXT); // ngat ngoai
ext_INT_edge(H_TO_L);
enable_interrupts ( GLOBAL ) ; // cho phep ng?t toan c?c
WHILE (true)
{
tocdodat = atof(string);
lcd_putcmd (0x80) ;
printf (lcd_putchar, "tocdo = %f",w);
printf (" %f\n\r", tocdo);
delay_ms (500);
IF (tocdo < tocdodat)
{
output_high (en) ;
output_low (ccp1) ;
output_high (ccp2) ;
lcd_putcmd (0xc0) ;
printf (lcd_putchar, "Che DO :0n-thuan");
}
IF (tocdo > tocdodat)
{
output_low (en) ;
lcd_putcmd (0xc0) ;
printf (lcd_putchar, "Che DO :0ff ");
}
}
}

