mấy anh giúp em với sao led chỉ chạy tới 1/2 chữ "A" thì lặp lại mà không chạy hết mà sao nó không chạy từ chữ "O"
//code chạy từ trái sang phải chữ "CHAO"
#include <mega8.h>
#include <delay.h>
#define SCK PORTB.5
#define DATA PORTB.3
#define SCL PORTB.0
#define A PORTC.0;
#define B PORTC.1;
#define C PORTC.2;
#define OutEn PORTC.3;
unsigned char Pattern1[8]={0,1,2,3,4,5,6,7};
const unsigned char CHAO[]={156,136,112,162,72,137,130,40,138,130,47,138,130 ,232,139,162,40,138,156,40,114,0,0,0};
unsigned char *DMem[8];
unsigned char *DMemBackup[8];
unsigned char *byte1st;
unsigned char *byteth;
unsigned char rowth=0;
unsigned char ncols=3;
unsigned char i,k,j,temp,nextdataready;
const unsigned char noled=3;
void datapreparing(void)
{
if(!nextdataready)
{
byte1st=DMem[rowth];
temp=*byte1st;
if(k!=0) temp<<=k;
for(j=k;j<=7;j++)
{
temp<<=1;
DATA=SREG.0;
SCK=0;
SCK=1;
}
if(k!=0)
{
byteth=byte1st+1;
temp=*byteth;
for(j=0;j<=k-1;j++)
{
temp<<=1;
DATA=SREG.0;
SCK=0;SCK=1;
}
}
nextdataready=1;
}
}
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
// Place your code here
PORTC.3=1;
SCL=0;
SCL=1;
PORTC=Pattern1[rowth];
PORTC.3=0;
rowth++;
if (rowth==8) rowth=0;
nextdataready=0;
datapreparing();
}
// Declare your global variables here
void main(void)
{
PORTB=0x00;
DDRB=0x2D;
PORTC=0x00;
DDRC=0x7F;
TCCR1A=0x00;
TCCR1B=0x0B;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x25;
OCR1BH=0x00;
OCR1BL=0x00;
TIMSK=0x10;
#asm("sei")
// Place your code here
for (i=0;i<=7;i++)
{
DMem[i]=CHAO+i*noled;
DMemBackup[i]=DMem[i];
}
while (1)
{
for(i=0;i<=7;i++)
{
DMem[i]=DMemBackup[i];
}
for(k=0;k<=7;k++)
{
delay_ms(200);
}
}
}
//code chạy từ trái sang phải chữ "CHAO"
#include <mega8.h>
#include <delay.h>
#define SCK PORTB.5
#define DATA PORTB.3
#define SCL PORTB.0
#define A PORTC.0;
#define B PORTC.1;
#define C PORTC.2;
#define OutEn PORTC.3;
unsigned char Pattern1[8]={0,1,2,3,4,5,6,7};
const unsigned char CHAO[]={156,136,112,162,72,137,130,40,138,130,47,138,130 ,232,139,162,40,138,156,40,114,0,0,0};
unsigned char *DMem[8];
unsigned char *DMemBackup[8];
unsigned char *byte1st;
unsigned char *byteth;
unsigned char rowth=0;
unsigned char ncols=3;
unsigned char i,k,j,temp,nextdataready;
const unsigned char noled=3;
void datapreparing(void)
{
if(!nextdataready)
{
byte1st=DMem[rowth];
temp=*byte1st;
if(k!=0) temp<<=k;
for(j=k;j<=7;j++)
{
temp<<=1;
DATA=SREG.0;
SCK=0;
SCK=1;
}
if(k!=0)
{
byteth=byte1st+1;
temp=*byteth;
for(j=0;j<=k-1;j++)
{
temp<<=1;
DATA=SREG.0;
SCK=0;SCK=1;
}
}
nextdataready=1;
}
}
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
// Place your code here
PORTC.3=1;
SCL=0;
SCL=1;
PORTC=Pattern1[rowth];
PORTC.3=0;
rowth++;
if (rowth==8) rowth=0;
nextdataready=0;
datapreparing();
}
// Declare your global variables here
void main(void)
{
PORTB=0x00;
DDRB=0x2D;
PORTC=0x00;
DDRC=0x7F;
TCCR1A=0x00;
TCCR1B=0x0B;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x25;
OCR1BH=0x00;
OCR1BL=0x00;
TIMSK=0x10;
#asm("sei")
// Place your code here
for (i=0;i<=7;i++)
{
DMem[i]=CHAO+i*noled;
DMemBackup[i]=DMem[i];
}
while (1)
{
for(i=0;i<=7;i++)
{
DMem[i]=DMemBackup[i];
}
for(k=0;k<=7;k++)
{
delay_ms(200);
}
}
}
Comment