m viet ct cho c18 dung p18f4550 led ma tran bao loi ai biet sua dum minh voi
#include <p18f4550.h>
#fuse NOWDT,HS,PUT,NOPROTECT
#device 18f4550 *=16 adc=8
#use delay(clock=20000000)
int8 y,i;
int8 Cot1[]={0b00001110, 0b00010001, 0b00000001, 0b00000001, 0b00000001, 0b00010001, 0b00001110};
int8 Cot2[]={0b00001110, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00000100, 0b00001110};
int8 Cot3[]={0b00001111, 0b00010001, 0b00010001, 0b00001111, 0b00000001, 0b00000001, 0b00000001};
int8 Dong[]={0b11111110, 0b11111101, 0b11111011, 0b11110111, 0b11101111, 0b11011111, 0b10111111};
void sen595(int8 x)
{
#bit fla=x.7;
output_high(PIN_B0);
for (i=0;i<8;i++)
{
if (fla==1)
output_high(PIN_B1); //Dich 1 bit vao 74HC595
else output_low(PIN_B1);
output_low(PIN_B0); //Tao xung Clock
output_high(PIN_B0); //tao xung Clock
x = x<<1; //Dich trai 1 bit cua Data
}
output_low(PIN_B2); //Chot 8 bit cho dau ra
output_high(PIN_B2); //Chot 8 bit cho dau ra
}
void main()
{
set_tris_b(0x00);
while(1)
{
for (y=0;y<7;y++)
{
sen595(Cot1[y]); //Gui ky tu C
sen595(Cot2[y]); //Gui ky tu I
sen595(Cot3[y]); //Gui ky tu P
output_d(Dong[y]);
delay_ms(50); //Tao thoi gian tre
}
}
}
delay_ms(8); //Tao thoi gian tre
output_d(0xff);
|