PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   PIC Việt Nam - Chuyên nghiệp (http://www.picvietnam.com/forum/forumdisplay.php?f=35)
-   -   Vấn đề về quyet led 7 đoạn dùng timer cần mọi người giúp đỡ ! (http://www.picvietnam.com/forum/showthread.php?t=32889)

lucky_luke 28-09-2013 03:08 AM

Vấn đề về quyet led 7 đoạn dùng timer cần mọi người giúp đỡ !
 
1 Attachment(s)
E mới đọc về pic, đang làm chương trình nguồn đo hiển thị dung lượng sạc pin hiển thị led 7 đoạn, quyét led dùng delay thì ok, còn quét dùng timer thì gặp vấn đề. e có gửi cả file mô phỏng và 2 file quyet dùng delay và timer, các pro xem & góp ý cho e với ! E cảm ơn !

#include <16f877a.h>
#include <def_16f877a.h>
#device *=16 ADC=10
#fuses NOPUT,NOWDT,HS,NOPROTECT
#use delay(clock=16000000)
#use fast_io(b)
#use fast_io(d)

int8 maled_dp[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xe f};
int8 maled[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6 f};
int16 x,y,z,s,p;
int8 Ah,mAh,count;
#int_timer1
void sac()
{
y=read_adc();
set_timer1(15535);
x++;
if(x>20)
{
x=0;++s;
if(s==60)
{
s=0;++p;
z=p*y*5/6000;
if(z>1)
{
p=0;++mAh;
if(mAh==10)
{++Ah;mAh=0;}
}
}

}
}
#int_timer0
void hienthi()
{
set_timer0(0);
++count;
if(count==4){count=0;}
switch(count)
{
case 0:
RB1=1;
DELAY_US(5);
PORTD=maled_dp[Ah];
RB1=0;
break;
case 1:
RB2=1;
DELAY_US(5);
PORTD=maled[mAh];
RB2=0;
break;
case 2:
RB3=1;
DELAY_US(5);
PORTD=0X77;
RB3=0;
case 3:
RB4=1;
DELAY_US(5);
PORTD=0X74;
RB4=0;
break;
}
}
void main()
{
trisb=0x00;
portb=0xff;
trisd=0x00;
portd=0x00;
count=0;
//khai bao i/o
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_TIMER1);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);
setup_timer_1(T2_DIV_BY_4 | T1_INTERNAL);
//khai bao timer0 & timer1
setup_adc(adc_clock_internal);//thoi gian lay mau 2-6us
setup_adc_ports(AN0_AN1_AN2_AN3_AN4);//AN0-AN1-AN2 nhan analog
set_adc_channel(1);//chon chan de doc
delay_ms(10);
//khai bao adc
while(1)
{
}
}


Múi giờ GMT. Hiện tại là 12:35 AM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam