![]() |
![]() |
#1 |
Đệ tử 1 túi
Tham gia ngày: Jun 2005
Bài gửi: 13
: |
Chương trình đọc encoder
Các bác cho em hỏi chương trình đọc encoder của em như thế này có ổn không vậy?
Với một vấn đề nữa là em dùng thạch anh 4MHz, nhưng em khai báo #FUSES XT thì nó không chạy được mà phải khai báo là HS, em không hiểu vì sao? Code:
#include "E:\Mo phong\Doc encoder\Doc encoder.h" #include "def_877a.h" #include<lcd_lib_4bit.c> #use delay(clock=4000000) int8 nghin,tram,chuc,donvi; int16 count,so_vong,int_count1,x; void tinhtoan_hienthi(int16 x); #define INTS_PER_SECOND1 4 #int_rtcc // Ngat Timer 0 void Timer0_isr() { count++; } #INT_TIMER1 // Chuong trinh ngat Timer 1 void Timer11_isr() { SET_TIMER1(12140); if(--int_count1==0) { int_count1 = INTS_PER_SECOND1; so_vong = (count*255 + get_timer0())*60/100; count = 0; set_timer0(0); } } void tinhtoan_hienthi(int16 x) // thuc hien tach so va dua ra hien thi luon { nghin = x / 1000 + 0x30; x = x % 1000; tram = x / 100 + 0x30; // tách so hang tram x = x % 100; // chia lay phan du chuc = x / 10 + 0x30; // tach lay phan chuc donvi = x % 10 + 0x30; // phan don vi lcd_putcmd(0xC0); printf(lcd_putchar,"toc do="); lcd_putchar(nghin); lcd_putchar(tram); lcd_putchar(chuc); lcd_putchar(donvi); } void init() { lcd_putcmd(0x80); int_count1 = INTS_PER_SECOND1;//4 lan 1 giay setup_timer_0 (RTCC_DIV_1|RTCC_EXT_H_TO_L); // Timer0 is Counter set_timer0(0); setup_timer_1(T1_INTERNAL | T1_DIV_BY_4); // Timer1 is Timer set_timer1(12140); enable_interrupts(INT_RTCC); enable_interrupts(INT_TIMER1); enable_interrupts(GLOBAL); count = 0; lcd_init(); delay_ms(200); printf(lcd_putchar,"toc do dong co"); } void main() { init(); so_vong = 0; // a = 0; TRISA = 0xFF; // trisB = 0xFF; // portb = 0xff; RD2 = 1; trisD = 0; // lcd_init(); // delay_ms(200); // printf(lcd_putchar,"Liencoi"); while(1) // doan chuong trinh hien thi len LCD { tinhtoan_hienthi(so_vong); delay_ms(500); } } |
![]() |
![]() |
Ðiều Chỉnh | |
Xếp Bài | |
|
|