51的1602移植到mega16上怎么就用不了?
[复制链接]
#define F_CPU 1000000UL #include<avr/io.h> #include<avr/interrupt.h> #include<util/delay.h> #define uchar unsigned char #define uint unsigned int //sbit rs=P2^4; //sbit rw=P2^5; //sbit e=P2^6;
#define rs PC4 #define rw PC5 #define e PC6
#define rs_0() (PORTC&=~_BV(rs)) #define rs_1() (PORTC|=_BV(rs)) #define rw_0() (PORTC&=~_BV(rw)) #define rw_1() (PORTC|=_BV(rw)) #define e_0() (PORTC&=~_BV(e)) #define e_1() (PORTC|=_BV(e))
uchar table1[]="welcome to cctv "; uchar table2[]="do anything"; uchar table[17];
void write_com(uchar com) { e_0(); rs_0(); rw_0(); PORTA=com; _delay_us(500); e_1(); _delay_us(1000); e_0(); }
void write_date(uchar dat) { e_0(); rs_1(); rw_0(); PORTA=dat; _delay_us(500); e_1(); _delay_us(1000); e_0(); }
void init() { DDRA=0XFF;PORTA=0XFF; DDRC=0XFF;PORTC=0XFF; _delay_ms(15); write_com(0x38); _delay_ms(5); write_com(0x38); _delay_ms(5); write_com(0x38); write_com(0x38); write_com(0x08); write_com(0x01); write_com(0x06); write_com(0x0c); } int main() { uchar j; init(); write_com(0x80); for(j=0;j<16;j++) { table[j]=table2[j]; write_date(table[j]); _delay_us(500); } write_com(0xc0); for(j=0;j<16;j++) { table[j]=table2[j]; write_date(table[j]); _delay_us(500); } while(1);
}
|