ATMEGA128 数码管显示存在故障
#define OE_PORT PORTC
#define OE_PIN PINC
#define OE_DDR DDRC
#define OE 7
#define SS 0
#define SCK 1
#define MOSI 2
#define MISO 3
#define Seg7_Bit0 4
#define Seg7_Bit1 5
#define Seg7_Bit2 6
#define Seg7_Bit3 7
#define dp 7
#define Seg7_Bitselect_PORT PORTB
#define Seg7_Bitselect_PIN PINB
#define Seg7_Bitselect_DDR DDRB
#define Seg7_Bit0_En() {Seg7_Bitselect_DDR|=(1<#define Seg7_Bit0_Dis() {Seg7_Bitselect_DDR|=(1<#define Seg7_Bit1_En() {Seg7_Bitselect_DDR|=(1<#define Seg7_Bit1_Dis() {Seg7_Bitselect_DDR|=(1<#define Seg7_Bit2_En() {Seg7_Bitselect_DDR|=(1<#define Seg7_Bit2_Dis() {Seg7_Bitselect_DDR|=(1<#define Seg7_Bit3_En() {Seg7_Bitselect_DDR|=(1<#define Seg7_Bit3_Dis() {Seg7_Bitselect_DDR|=(1<//#define SS_H() PORTB|=(1<//#define SS_L() PORTB&=~(1<#include
const unsigned char tt[]={0x3F,0x06,0x5B,0x4F,0x66, //0,1,2,3,4
0x6D,0x7D,0x07,0x7F,0x6F}; //5,6,7,8,9
unsigned char buffer;
void spi_init()
{
DDRB |= (1< SPCR = (1<}
/*************************************************************************
** 函数名称: SPI_MasterTransmit(char Data)
** 功能描述: SPI主机发送数据
** 输 入: Data 需要通过SPI传输的数据
** 输出 :
** 全局变量: 无
** 调用模块:
** 说明:
** 注意:
**************************************************************************/
void SPI_MasterTransmit(char Data)
{
/* 启动数据传输 */
SPDR = Data;
/* 等待传输结束 */
while(!(SPSR & (1< ;
}
void HC_595_init(void)
{
OE_DDR |= (1< OE_PORT &= (1< PORTB = 0xf0;
spi_init();
}
void init_device()
{
//spi_init();
HC_595_init();
}
void HC_595_OUT(unsigned char data)
{
//SS_L();
PORTB=0xff;
SPI_MasterTransmit(data);
//SS_H();
}
void delay( unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=1140;y>0;y--);
}
void delay1(unsigned int z)
{
while(z--);
}
void main()
{
unsigned int cnt;
init_device();
while(1)
{
for(cnt=0;cnt<10;cnt++)
{
buffer=tt[cnt];
HC_595_OUT(buffer);
Seg7_Bit0_En();
delay(300);
Seg7_Bit0_Dis();
//delay(300);
}
}
}
阅读(918) | 评论(0) | 转发(0) |