PDA

View Full Version : cần giúp quang báo bằng ccs


tungtot_vl
16-10-2007, 03:51 PM
em viết bài quang báo. định viết để hiện thị cho 8 led (64 cột) 2 hàng, có cả font đầy đủ cho tiếng việt. kích thước chữ 16 byte (quét 2 hàng). nhưng khi mới viết được cho 4 led thì chữ chạy giật nhiều quá. nếu giảm delay_us(1000) còn 900 thì khi mô phỏng không thấy gì cả. em cũng định dùng timer nhưng chưa biết sài. có cách nào khắc phục hiện tượng giật thì các anh giúp em với


// kiem tra mach led matrix cho 4 led cho 2 hang 32 cot
// cot duong hang am
// goi tu pc xuong cac so thap phan de chon font hien thi ky tu

#include<16F877a.h>
#fuses NOLVP,NOWDT,PUT,hs,NOPROTECT
#use delay(clock=20000000)
//#device*= 16 adc = 8
//#include<fonta.c>
#use fast_io(a)
#byte porta=0x05
#use fast_io(b)
#byte portb=0x06
#use fast_io(c)
#byte portc=0x07
#use fast_io(d)
#byte portd=0x08
#use fast_io(e)
#byte porte=0x09
#bit rc0 = portc.0
#bit rc1 = portc.1
//================================================== ====
int const q=4,t=4; // so chu can hien thi, so led ma?tix duoc dung

unsigned char const chu[] ={7,8,13,7};
unsigned int tam2[q*8],tam1[q*8],ht2[32],ht1[32];
//unsigned int
//unsigned char n,dex,i,a,b,k,j,x;

unsigned char const fontto[] = {0x3f,0xdf,0xef,0xef,0xef,0xdf,0x3f,0xff, // A 0
0x80,0xfd,0xfd,0xfd,0xfd,0xfd,0x80,0xff // A
0x0f,0xef,0xef,0xef,0xef,0xdf,0x3f,0xff, // B 16
0x80,0xbd,0xbd,0xbd,0xbd,0xdb,0xe7,0xff, // B
0x3f,0xdf,0xef,0xef,0xef,0xdf,0xbf,0xff, // C 32
0xe0,0xdf,0xbf,0xbf,0xbf,0xdf,0xef,0xff, // C
0x0f,0xef,0xef,0xef,0xef,0xdf,0x3f,0xff, // D 48
0x80,0xbf,0xbf,0xbf,0xbf,0xdf,0xe0,0xff, // D
0x0f,0xef,0xef,0xef,0xef,0xef,0xef,0xff, // E 64
0x80,0xbd,0xbd,0xbd,0xbd,0xbd,0xbf,0xff, // E
0x0f,0xef,0xef,0xef,0xef,0xef,0xef,0xff, // F 80
0x80,0xfd,0xfd,0xfd,0xfd,0xfd,0xff,0xff, // F
0x3f,0xdf,0xef,0xef,0xef,0xdf,0xbf,0xff, // G 96
0xe0,0xdf,0xbf,0xbf,0xbf,0xdb,0x13,0xff, // G
0x0F,0xFf,0xFf,0xFf,0xFf,0xFf,0x0f,0xff, // H 112
0x80,0xFD,0xFD,0xFD,0xFD,0xFD,0x80,0xff, // H
0xef,0xef,0xef,0x0f,0xef,0xef,0xef,0xff, // I 128
0xbf,0xbf,0xbf,0x80,0xbf,0xbf,0xbf,0xff, // I
0xef,0xef,0xef,0xef,0x0f,0xef,0xef,0xff, // J 144
0xdf,0xbf,0xbf,0xbf,0xc0,0xff,0xff,0xff, // J
0x0f,0xff,0xff,0x7f,0xbf,0xdf,0xEf,0xff, // K 160
0x80,0xfd,0xfa,0xf7,0xef,0xdf,0xbf,0xff, // K
0x0f,0xff,0xff,0xff,0xff,0xff,0xff,0xff, // L 176
0x80,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xff, // L
0x0f,0xdf,0xbf,0x7f,0xbf,0xdf,0x0f,0xff, // M 192
0x80,0xff,0xff,0xff,0xff,0xfb,0x80,0xff, // M
0x0f,0xdf,0xbf,0x7f,0xff,0xff,0x0f,0xff, // N 208
0x80,0xff,0xff,0xff,0xfe,0xfd,0x80,0xff, // N
0x0f,0xff,0xff,0xff,0xff,0xff,0x0f,0xff, // v 224
0xe0,0xdf,0xbf,0x7f,0xbf,0xdf,0xe0,0xff, // v
};

//================================================== =======
void trabang()
{ int8 m,p;
int16 w; // dia chi cua cac chu trong font
for(m = 0; m < q; m++) // vong lap de tim vi tri cac chu trong font
{
switch(chu[m])
{
case 0: w = 0; break; //A
case 1: w = 16; break; //B
case 2: w = 32; break; //C
case 3: w = 48; break; //D
case 4: w = 64; break; //E
case 5: w = 80; break; //F
case 6: w = 96; break; //G
case 7: w = 112; break; //H
case 8: w = 128; break; //I
case 9: w = 144; break; //J
case 10: w = 160; break; //K
case 11: w = 176; break; //L
case 12: w = 192; break; //M
case 13: w = 208; break; //N
case 14: w = 224; break; //N
}
for(p=0;p<8;p++)
{
tam1[m*8+p] = fontto[w+p]; // gan chu hang 1 vao tam1
tam2[m*8+p] = fontto[w+p+8]; // gan chu hang 2 vao tam2

}
}
}

//------------------------------------------------------
void dislay()
{
int8 i,l;
// quet hang 1
for(l=0;l<5;l++) // thoi gian dich chu
{
rc0=0;rc1=1;
for(i=0;i<t*8;i++) // quet cot
{
portd =i;
portb = ht1[i];
delay_us(1000);
portb = 0xff;
}


//--------------------------------------------
// quet hang 2
rc0=1;rc1=0;
for(i=0;i<t*8;i++) // quet cot
{
portd =i;
portb = ht2[i];
delay_us(1000);
portb = 0xff;
}
}
}
//================================================== ===
void main()
{unsigned int a,b,x,y,z;

set_tris_b(0);
set_tris_a(0);
set_tris_c(0);
set_tris_e(0);
set_tris_d(0);
for(a=0;a<q*8;a++){tam1[a]=0xff;tam2[a]=0xff;}
trabang();
while(true)
{
portb = 0xff;
portb = 0;
rc0 =1; rc1 = 1;
//--------------------------------------------
for(b=0;b<t*8;b++){ht1[b]=0xff;ht2[b]=0xff;} // xoa man hinh
for(x=0;x<(q+t)*8;x++)//< chieu dai chuoi + chieu dai led hien thi
{
for(y=(t*8-1);y>0;y--)
{ ht1[y] = ht1[y-1];} // dich phai man hinh hien thi hang 1

for(z=(t*8-1);z>0;z--)
{ ht2[z] = ht2[z-1];} // dich phai man hinh hien thi hang 2
if(x<q*8) {ht1[0] = tam1[q*8-1-x]; ht2[0] = tam2[q*8-1-x];} // chieu dai chuoi chu
else {ht1[0] = 0xff;ht2[0] = 0xff;}
dislay();
}
// delay_ms(1000);
}
}
//=============================================
à. em đinh đổi con 877a thành con 18f4550 nhưng không biết có cần thay đổi gì không hả các anh. vì con 18f em chưa dùng nên chưa biết làm thế nào