//用AVR点亮32*32LED点阵 点阵里集成74hc595 和74hc138芯片 #include #includetil/delay.h> #include #include #define SI1 PORTC|=(1< 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; unsigned char scan_date1[32]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f}; //行 void delay(unsigned int ms ) { while(ms--) _delay_ms(1); } //初始化函数 void init() { //HC_595初始化 DDRC=0x1F; PORTC=0xFF; G0() ; //使能HC_595输出使能控制端 SCK0(); // HC_595移位寄存器时钟输入端口置低电平 RCK0(); SCLR0(); SCLR1(); // HC_595存储寄存器时钟输入 //HC_138初始化 DDRA=0x3F; PORTA=0xFF; } //HC_595列扫描 void HC_595( unsigned int date) { unsigned char i; for(i=0;i<8;i++) { G0(); SCK0(); if(date&0x80) PORTC|=(1< PORTC&=~(1< date<<=1; SCK1(); } RCK0(); //上升沿锁存数据输出 RCK1(); G1(); //关闭输出使能控制端 } int main() { init(); unsigned int i=0; unsigned int m=3; unsigned int n=0; for(i=0;i<=31;i++) { OE0(); //打开HC_138使能 PORTA=scan_date1; for(n=m-3;n<=m;n++) { if(n<=127) { HC_595(scan_date0[n]); m=m+4; } delay(4); } // OE1(); //关闭HC_138使能 } } |
更多回帖