所以经过大量调试后,我终于成功构建了我的代码,但是当我去 proteus 并将十六进制代码提供给 ATMega32 时,它说这部分存在问题: LCD1_D5 Passive U1_PA5/AD ... 在 Proteus 中,我将所有部分连接为老师说所以我不明白这个问题...应该做的是,按下按钮后,7segment从9数到0,然后LCD上会写一些东西。
#include <avr/io.h>
#include <util/delay.h>
#include <LCD.h>
int main(void){
int seg_counter=10;
unsigned char i, word[20]="Mission Complete";
unsigned char seg[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
DDRC = (1<<DDC7) | (1<<DDC6) | (1<<DDC5) | (1<<DDC4) | (1<<DDC3) | (1<<DDC2) | (1<<DDC1) | (1<<DDC0); //7segment
DDRD = (0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) | (1<<DDD0); //button: input
PORTD = (1<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0); //for pull up portd0=1
PORTC = (0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);
DDRA=0xFF; //1=output
DDRB=0x07; //0=input
init_LCD();
LCD_cmd(0x0F); // cursor blinks
_delay_ms(1000);
LCD_cmd(0x14); // Move cursor to the right
if (((PIND>>PIND0) & 1) == 0)
{
_delay_ms(1000);
PORTD |= (1<<PORTD0); //start
if (seg_counter<9)
{
PORTC=seg[seg_counter];
_delay_ms(1000);
seg_counter--;
if (seg_counter==0)
{
for(i=0;i<16;i++) //LCD Write
LCD_write(word[i]);
_delay_ms(10);
}
}
}
}