PDA

View Full Version : hiển thị led 7 đoạn


daklak
19-03-2012, 08:47 PM
mình có viết 1 đoạn code dùng ngôn ngữ ccs hiển thị số từ 0 dến9 ra led 7 đoạn nhưng mà không chạy được bạn nào rảnh coi giúp mình lối của chương trình


#include "p18f4620.h"
#include "delays.h"
#pragma config OSC=HS,WDT=OFF
#defined led_don PORTC
void delay(void)
{
int i;
for(i=0;i<8000;i++)
void main(void)
{
TRISB=0;chon B la cong ra
TRISC=0XFF;

while(1)
{
if(PORTC==0X00)
PORTB=0X40
else if(PORTC==0X01)
{PORTB=0X79;}
esle if(PORTC==0X02)
{PORTB=0X24;}
else if(PORTC==0X03)
{PORTB=0X030;}
else if(PORTC==0X04)
{PORTB=0X19;
else if(PORTC==0X05)
{PORTB=0X12;}
else if(PORTC==0X06)
{PORTB=0X02;}
else if(PORTC==0X07)
{PORTB=0X78;}
else if(PORTC==0X08)
{PORTB=0X00;}
else if(PORTC==0X09)
{PORTB=0X10;}
}
}
}

thanhchuyen@
01-04-2012, 06:25 PM
#include "p18f4620.h"
#include"delays.h"
#pragma config OSC=HS,WDT=OFF
void delay(void)
{
int i;
for (i=0;i<800;i++)
;
}
void main(void)
{
TRISB=0x00;
TRISC=0xff;
while(1)
{
if (PORTC==0x00)
PORTB=0x03;
else if(PORTC==0x01)
PORTB=0x9f;
else if (PORTC==0x02)
PORTB=0x25;
else if (PORTC==0x03)
PORTB=0x0d;
else if (PORTC==0x04)
PORTB=0x99;
else if (PORTC==0x05)
PORTB=0x49;
else if (PORTC==0x06)
PORTB=0x41;
else if (PORTC==0x07)
PORTB=0x1f;
else if (PORTC==0x08)
PORTB=0x00;
else if (PORTC==0x09)
PORTB=0x09;
else(PORTB=0xff);
}
}