#include <P18F4550.h>
#include <delays.h>
#define den1 PORTAbits.RA0
#define den2 PORTAbits.RA1
unsigned char Display(unsigned char k)
{
unsigned char Number;
unsigned char Code_Tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x9 0,0x7F};
Number=Code_Tab[k];
return(Number);
}
void main()
{
unsigned char Msd,Lsd,Value;
unsigned int i,j;
TRISA=0x00;
TRISD=0x00;
den1=0;
den2=0;
for(
{
for(Value=0;Value<100;Value++)
{
for(i=0;i<80;i++)
{
Msd=Value/10;
Lsd=Value%10;
PORTD=Display(Msd);
den2=1;
Delay100TCYx(250);
den2=0;
PORTD=Display(Lsd);
den1=1;
Delay100TCYx(250);
den1=0;
}
}
}
}
E sử dụng thạch anh 16MHz
#include <delays.h>
#define den1 PORTAbits.RA0
#define den2 PORTAbits.RA1
unsigned char Display(unsigned char k)
{
unsigned char Number;
unsigned char Code_Tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x9 0,0x7F};
Number=Code_Tab[k];
return(Number);
}
void main()
{
unsigned char Msd,Lsd,Value;
unsigned int i,j;
TRISA=0x00;
TRISD=0x00;
den1=0;
den2=0;
for(
{
for(Value=0;Value<100;Value++)
{
for(i=0;i<80;i++)
{
Msd=Value/10;
Lsd=Value%10;
PORTD=Display(Msd);
den2=1;
Delay100TCYx(250);
den2=0;
PORTD=Display(Lsd);
den1=1;
Delay100TCYx(250);
den1=0;
}
}
}
}
E sử dụng thạch anh 16MHz