e sử dụng động cơ DC 12v 1 vòng 200xung...ai bít chỉ giùm e với...sao e viết hoài mà không chạy
#include <16F877A.h>
#device *=16
#DEVICE ADC = 10
#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 NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES RESERVED //Used to set the reserved FUSE bit
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8)
#define LCD_ENABLE_PIN PIN_D2
#define LCD_RS_PIN PIN_D1
#define LCD_RW_PIN PIN_D0
#define LCD_DATA4 PIN_D3
#define LCD_DATA5 PIN_D4
#define LCD_DATA6 PIN_D5
#define LCD_DATA7 PIN_D6
#INCLUDE <LCD.C>
float sovong,v;
float xung =200;
int32 dem;
int32 counterb;
#int_ext
void ngat_ngoai(){
counterb=counterb+1;//nhan so xung vao
}
#INT_TIMER1
void Sampling_Time()
{
disable_interrupts (INT_EXT);
set_timer1(59286);
dem ++ ;
if(dem==5000)
{
dem=0;
v=(float)counterb*30;
enable_interrupts(INT_EXT);
}
}
//================================================== ==========================
void main()
{
SET_TRIS_D(0);
SET_TRIS_B(0xff);
set_timer1(59286);
enable_interrupts(INT_EXT);
EXT_INT_EDGE(H_TO_L);
while(1)
{
lcd_init();
lcd_gotoxy(1,1);
printf(lcd_putc,"TocDo=%f",sovong);
lcd_gotoxy(13,1);
printf(lcd_putc,"V/P");
enable_interrupts(GlOBAL);
delay_ms(100);//t1
disable_interrupts(GlOBAL);
sovong=(v/xung)*600;//t=t1*600=100*600=60000ms=60s=1phut ( van toc = vong/phut)
lcd_gotoxy(1,2);
printf(lcd_putc,"%f",sovong);
v=0;
enable_interrupts(GlOBAL);
}
}
#include <16F877A.h>
#device *=16
#DEVICE ADC = 10
#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 NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES RESERVED //Used to set the reserved FUSE bit
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8)
#define LCD_ENABLE_PIN PIN_D2
#define LCD_RS_PIN PIN_D1
#define LCD_RW_PIN PIN_D0
#define LCD_DATA4 PIN_D3
#define LCD_DATA5 PIN_D4
#define LCD_DATA6 PIN_D5
#define LCD_DATA7 PIN_D6
#INCLUDE <LCD.C>
float sovong,v;
float xung =200;
int32 dem;
int32 counterb;
#int_ext
void ngat_ngoai(){
counterb=counterb+1;//nhan so xung vao
}
#INT_TIMER1
void Sampling_Time()
{
disable_interrupts (INT_EXT);
set_timer1(59286);
dem ++ ;
if(dem==5000)
{
dem=0;
v=(float)counterb*30;
enable_interrupts(INT_EXT);
}
}
//================================================== ==========================
void main()
{
SET_TRIS_D(0);
SET_TRIS_B(0xff);
set_timer1(59286);
enable_interrupts(INT_EXT);
EXT_INT_EDGE(H_TO_L);
while(1)
{
lcd_init();
lcd_gotoxy(1,1);
printf(lcd_putc,"TocDo=%f",sovong);
lcd_gotoxy(13,1);
printf(lcd_putc,"V/P");
enable_interrupts(GlOBAL);
delay_ms(100);//t1
disable_interrupts(GlOBAL);
sovong=(v/xung)*600;//t=t1*600=100*600=60000ms=60s=1phut ( van toc = vong/phut)
lcd_gotoxy(1,2);
printf(lcd_putc,"%f",sovong);
v=0;
enable_interrupts(GlOBAL);
}
}