em nạp vô nhưng ko thấy led sáng chữ chạy mong các bác xem giúp em làm sai chỗ nào với
#include <mega8.h>
#include <delay.h>
// SPI functions
#include <spi.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};
unsigned char flash chu_c[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 60,126,195,195,255,195,195,0};
unsigned char DMem[8]; // Bo nho man hinh, 3 byte dau cho hang 1, 3 byte tiep theo cho hang 2 ...
unsigned char i=0,rr,r=0;
unsigned char k;
void LatchData()
{
SCL=0;
SCL=1;
}
// Timer1 output compare A interrupt service routine
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
// Place your code here
//spi(DMem[r*3+2]);
//spi(DMem[r*3+1]);
spi(DMem[r]);
PORTC.3=1;
LatchData();
PORTC=Pattern1[r];
PORTC.3=0;
r++;
if (r==8)
{
r=0;
}
}
// Declare your global variables here
void main(void)
{
PORTB=0x00;
DDRB=0x2D;
PORTC=0x00;
DDRC=0x7F;
PORTD=0x00;
DDRD=0x00;
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 15.625 kHz
// Mode: CTC top=OCR1A
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: On
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x09;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x25;
OCR1BH=0x00;
OCR1BL=0x00;
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
MCUCR=0x00;
TIMSK=0x10;
UCSRB=0x00;
ACSR=0x80;
SFIOR=0x00;
ADCSRA=0x00;
// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 250.000 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x54;
SPSR=0x00;
TWCR=0x00;
#asm("sei")
// Place your code here
//for (i=0;i<=7;i++)
//{
//DMem[i]=~chu_c[i];
//}
while (1)
{
for (k=0;k<=7;k++)
{
DMem[k]=~(chu_c[i*8+k]>>rr);
}
rr++;
if (rr==8)
{
rr=0;
}
i++;
if (i==3) i=0;
delay_ms(100);
}
}
#include <mega8.h>
#include <delay.h>
// SPI functions
#include <spi.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};
unsigned char flash chu_c[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 60,126,195,195,255,195,195,0};
unsigned char DMem[8]; // Bo nho man hinh, 3 byte dau cho hang 1, 3 byte tiep theo cho hang 2 ...
unsigned char i=0,rr,r=0;
unsigned char k;
void LatchData()
{
SCL=0;
SCL=1;
}
// Timer1 output compare A interrupt service routine
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{
// Place your code here
//spi(DMem[r*3+2]);
//spi(DMem[r*3+1]);
spi(DMem[r]);
PORTC.3=1;
LatchData();
PORTC=Pattern1[r];
PORTC.3=0;
r++;
if (r==8)
{
r=0;
}
}
// Declare your global variables here
void main(void)
{
PORTB=0x00;
DDRB=0x2D;
PORTC=0x00;
DDRC=0x7F;
PORTD=0x00;
DDRD=0x00;
TCCR0=0x00;
TCNT0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 15.625 kHz
// Mode: CTC top=OCR1A
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: On
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x09;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x25;
OCR1BH=0x00;
OCR1BL=0x00;
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
MCUCR=0x00;
TIMSK=0x10;
UCSRB=0x00;
ACSR=0x80;
SFIOR=0x00;
ADCSRA=0x00;
// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 250.000 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x54;
SPSR=0x00;
TWCR=0x00;
#asm("sei")
// Place your code here
//for (i=0;i<=7;i++)
//{
//DMem[i]=~chu_c[i];
//}
while (1)
{
for (k=0;k<=7;k++)
{
DMem[k]=~(chu_c[i*8+k]>>rr);
}
rr++;
if (rr==8)
{
rr=0;
}
i++;
if (i==3) i=0;
delay_ms(100);
}
}
Comment