74HC595是串转并芯片。它的特点是锁存数据,所以用它来驱动LED没有闪炼感。
以下是Proteus运行的载图:
Stduio6.2编译通过的结果。
程序清单:
/*
* GccApplication18.c
*
* Created: 2014-11-17 21:03:06
* Author: Administrator
*/
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <stdint.h>
//管脚定义
#define SH_CP PC0
#define DS PC1
#define SP_CP PC3
#define SH_CP_0() PORTC &= ~_BV(SH_CP)
#define SH_CP_1() PORTC |= _BV(SH_CP)
#define DS_0() PORTC &= ~_BV(DS)
#define DS_1() PORTC |=_BV(DS)
#define ST_CP_0() PORTC &=~_BV(SP_CP)
#define ST_CP_1() PORTC |= _BV(SP_CP)
const uint8_t SEG_CODE[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void Serial_Input_595(uint8_t dat)
{
uint8_t i;
for(i = 0;i<8;i++)
{
if(dat & 0x80) DS_1(); else DS_0();
dat <<= i;
SH_CP_0(); _delay_us(2);
SH_CP_1(); _delay_us(2);
SH_CP_0(); _delay_us(2);
}
}
void Paraller_Output_595()
{
ST_CP_0(); _delay_us(1);
ST_CP_1(); _delay_us(1);
ST_CP_0(); _delay_us(1);
}
int main(void)
{
uint8_t i=0;
DDRC = 0xFF;
while(1)
{
for(i = 0;i<10;i++)
{
Serial_Input_595(SEG_CODE[i]);
Paraller_Output_595();
_delay_ms(300);
}
//TODO:: Please write your application code
}
}
|