https://lh3.googleusercontent.com/-zUspaE2fgvg/VVWss3VdBRI/AAAAAAAAA9s/lGMx70vcPcU/SangTaoClub.Net-gsg.png
#include <mega16.h>
#include <delay.h>
#include <stdio.h>
#include <spi.h>
#define SCL PORTB.3
unsigned char flash FONT []={0,
62,65,65,65,62,0, //0 1
17,33,127,1,1,0, //1 2
35,69,73,73,49,0, //2 3
34,65,73,73,54,0, //3 4
12,20,36,79,4,0, //4 5
114,73,73,73,70,0, //5 6
62,73,73,73,38,0, //6 7
65,66,68,72,112,0, //7 8
54,73,73,73,54,0, //8 9
50,73,73,73,62,0, //9 10
63,68,68,68,63,0, //A 11
127,73,73,73,54,0, //B 12
62,65,65,65,34,0, //C 13
127,65,65,65,62,0, //D 14
127,73,73,73,65,0, //E 15
127,72,72,72,64,0, //F 16
62,65,73,73,46,0, //G 17
127,8,8,8,127,0, //H 18
65,65,127,65,65,0, //I 19
70,65,65,126,64,0, //J 20
127,8,20,34,65,0, //K 21
127,1,1,1,1,0, //L 22
127,32,24,32,127,0, //M 23
127,32,16,8,127,0, //N 24
62,65,65,65,62,0, //O 25
127,68,68,68,56,0, //P 26
62,65,69,66,61,0, //Q 27
127,68,68,74,49,0, //R 28
50,73,73,73,38,0, //S 29
64,64,127,64,64,0, //T 30
126,1,1,1,126,0, //U 31
124,2,1,2,124,0, //V 31
127,2,12,2,127,0, //W 33
65,34,28,34,65,0, //X 34
96,16,15,16,96,0, //Y 35
67,69,73,81,97,0, //Z 36
4,42,42,42,28,0, //a 37
126,18,18,18,12,0, //b 38
28,34,34,34,20,0, //c 39
12,18,18,20,126,0, //d 40
28,42,42,16,0,0, //e 41
4,62,72,64,32,0, //f 42
24,37,37,37,30,0, //g 43
126,16,16,16,14,0, //h 44
0,92,2,2,4,0, //i 45
4,2,2,92,0,0, //j 46
126,8,20,34,0,0, //k 47
124,2,2,2,0,0, //l 48
30,32,30,32,30,0, //m 49
62,8,16,62,0,0, //n 50
28,34,34,34,28,0, //o 51
31,36,36,36,24,0, //p 52
24,36,36,36,31,0, //q 53
0,30,32,32,24,0, //r 54
18,42,42,42,36,0, //s 55
0,32,124,34,4,0, //t 56
60,2,2,2,60,0, //u 57
56,4,2,4,56,0, //v 58
56,2,12,2,56,0, //w 59
34,20,8,20,34,0, //x 60
48,8,14,8,48,0, //y 61
34,38,42,50,34,0, //z 62
0,0,0,0,0,0, //
255};
unsigned char dong1[192],dong2[192];
unsigned char tocdo_quet=50,tocdo_chay=3,c,col=2,eff=1,sc=0,sp=0;
unsigned char tg,m=0,t=0,k=0,i,j,sokt=4,sokt1=4,sokt2=4;
unsigned char chuoi1[16]={8,8,8,8,8,8,8,8};
unsigned char chuoi2[16]={6,6,6,6,6,6,6,6};
void main(void){
lm1();
lm2();
// Timer/Counter 1 khởi chạy
// Clock source: System Clock
// Clock value: clk/256 kHz
// Mode: CTC top=OCR1A
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: On
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x0C;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=tocdo_quet;
OCR1BH=0x00;
OCR1BL=0x00;
/*UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x19;*/
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x47;
DDRB=0xFF;
DDRC=0xFF;
DDRA=0xFF;
SCL=1;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x10;
// Global enable interrupts
#asm("sei")
// SPI initialization
// SPI Type: Master
// SPI Clock Rate: clk
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x50;
SPSR=0x00;
while (1){
unsigned char temp1,temp2,length;
int i;
temp1 = getchar();
if (temp1=='A')
{
TIMSK=0x00;
//Nhan chuoi ky tu hang 1
//tinh do dai chuoi
temp1 = getchar()-48;
temp2 = getchar()-48;
length = temp1*10 temp2;
sokt1=length;
//Nhan chuoi ky tu
if (length >=1){
for( i=0;i<length;i )
{
chuoi1[i] = getchar();
}
xulychuoi();
lm1();
lm2();
t=0;
c=0;
TIMSK=0x10;
}
}
}
}
}
void LatchData(){
SCL=0;
SCL=1;
}
void lm1() {
for (i=0;i<=sokt1-1;i ){
for (j=0;j<=5;j ) {
dong1[i*6 j]=~FONT[chuoi1[i]*6 j 1];
}
}
}
void lm2(){
for (i=0;i<=sokt1*6-1;i ){
dong1[i sokt1*6]=dong1[i];
//dong1[i]=0;
dong1[i]=255;
}
}
void xulychuoi(){
for (i=0;i<sokt1;i ) {
if ((chuoi1[i]>47)&&(chuoi1[i]<58)) chuoi1[i]=chuoi1[i]-48;
else if ((chuoi1[i]>64)&&(chuoi1[i]<91)) chuoi1[i]=chuoi1[i]-55;
else if ((chuoi1[i]>96)&&(chuoi1[i]<123)) chuoi1[i]=chuoi1[i]-60;
else chuoi1[i]=62;
}
}
void shiftleft(){
for (i=0;i<sokt1*12-1;i ){
dong1[i]=dong1[i 1];
}
//dong1[sokt1*12-1]=0;
dong1[sokt1*12-1]=255;
}
void shiftright(){
tg= dong1[sokt*12-1];
for (i=sokt1*12-1;i>0;i--){
dong1[i]=dong1[i-1];}
dong1[0]=tg;
void tungchu () {
for (i=0;i<k*6;i ){
dong1[i]=dong1[sokt*6 i];
}
}