PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > PIC - Thiết kế và Ứng dụng

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

PIC - Thiết kế và Ứng dụng Ý tưởng cho các sản phẩm sử dụng PIC/dsPIC và các sản phẩm của Microchip

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 26-11-2012, 01:08 AM   #1
trunghieu266
Nhập môn đệ tử
 
Tham gia ngày: Nov 2012
Bài gửi: 1
:
Unhappy PIC16F877A Mạch đếm số người ra/vào phòng

các bác xem dùm cái code trên sửa thế nào: mình định hạn chế số người đi vào trên 100 thì sẽ không đếm nữa mà khi chạy mô phỏng và chạy ra mạch thật đều ko được, nó đếm hẳn lên mấy ngàn @@:
#include<16f877a.h>
#Fuses HS,NOLVP,NOPUT,NOWDT
#use delay(clock=12000000)
#use fast_io(b)
#use fast_io(d)
#byte RB = 0x06
#bit RB7 = RB.7
#byte RD = 0x08
#bit G = RD.3
int8 maled[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x9 0};
int8 maG[10]={1,1,0,0,0,0,0,1,0,0};
signed int16 i, tram, nghin, chuc,donvi,n=0;
int1 s1=0,s2=0;
#INT_EXT
void demtien()
{
s1=1;
if(s2==1)
{
i++;
if(i==100) i=100;// đoạn này đây ạ!
s1=0;
s2=0;
disable_interrupts(INT_TIMER0);
}
else
{
enable_interrupts(INT_TIMER0);
set_timer0(0);
n=0;
}
}
#INT_RB
void ngat()
{
if(RB7==0)
{
s2=1;
if(s1==1)
{
i--;
if(i<0) i=0;
s1=s2=0;
disable_interrupts(INT_TIMER0);
}
else
{
enable_interrupts(INT_TIMER0);
set_timer0(0);
n=0;
}
disable_interrupts(INT_RB);
}
}
#INT_TIMER0
void ngat_timer0()
{
n++;
if(n==220)
{
n=0;
if(((s1==1)&&(s2==0))||((s1==0)&&(s2==1)))
s1=s2=0;
disable_interrupts(INT_TIMER0);
}
set_timer0(0);
}
void hienthi(int16 a)
{
nghin = a/1000;
tram = (a%1000)/100;
chuc = ((a%1000)%100)/10;
donvi = ((a%1000)%100)%10;
//===================
output_high(PIN_D4);
output_b((maled[nghin]<<1)|0x81);G=maG[nghin];
delay_ms(1);
output_low(PIN_D4);
output_b(0xFF);
//================
output_high(PIN_D5);
output_b((maled[tram]<<1)|0x81);G=maG[tram];
delay_ms(1);
output_low(PIN_D5);
output_b(0xFF);
//===============
output_high(PIN_D6);
output_b((maled[chuc]<<1)|0x81);G=maG[chuc];
delay_ms(1);
output_low(PIN_D6);
output_b(0xFF);
//==================
output_high(PIN_D7);
output_b((maled[donvi]<<1)|0x81);G=maG[donvi];
delay_ms(1);
output_low(PIN_D7);
output_b(0xFF);
}
void khoitao()
{
set_tris_b(0x81);
set_tris_d(0x00);
enable_interrupts(global);
enable_interrupts(INT_EXT);
enable_interrupts(H_to_L);
enable_interrupts(INT_RB);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
i=0;
}
void main()
{
khoitao();
while(true)
{
hienthi(i);
if(RB7==1) enable_interrupts(INT_RB);
}

}
trunghieu266 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 02:54 PM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam