在驱动时 点不亮,只在头一次通电时闪烁一下,后来就在不亮了,找不到毛病在哪里
程序清单如下
/*******************************/
//ICCAVR 7.22 2012-1212
/*******************************/
#include <ioM16v.h>
#include <macros.h>
/*------宏定义------*/
#define uchar unsigned char
#define uint unsigned int
/*端口定义*/
//包含所需头文件
/**************max7219定义*************
#define LOAD7219_1() PORTB|=(1<<PORTB0) // PORTC|=(1<<PORTC1)
#define LOAD7219_0() PORTB&=~(1<<PORTB0)// PORTC&=~(1<<PORTC1)
#define DIN7219_1() PORTB|=(1<<PORTB2) //PORTD|=(1<<PORTD0)
#define DIN7219_0() PORTB&=~(1<<PORTB2)// PORTD&=~(1<<PORTD0)
#define CLK7219_1() PORTB|=(1<<PORTB1) // PORTD|=(1<<PORTD1)
#define CLK7219_0() PORTB&=~(1<<PORTB1) // PORTD&=~(1<<PORTD1)
*/
//
#define LOAD7219_1() PORTC|=(1<<PORTC1)
#define LOAD7219_0() PORTC&=~(1<<PORTC1)
#define DIN7219_1() PORTD|=(1<<PORTD0)
#define DIN7219_0() PORTD&=~(1<<PORTD0)
#define CLK7219_1() PORTD|=(1<<PORTD1)
#define CLK7219_0() PORTD&=~(1<<PORTD1)
//
#define decode_add 0x09 //控制寄存器地址 内容为1时为BCD译码方式,为0时不译码
#define led_add 0x0a //亮度控制寄存器 1-32
#define bit_add 0x0b //扫描位数寄存器0-7 显示1-8位
#define stop_add 0x0c //D0=0关闭显示 需250uS才能退出 D0=1启动显示
#define ceshi_add 0x0f //测试7219以最亮方式全部点亮
#define null_add 0x00 //空操作寄存器
#define data1_add 0x01 //数字寄存器
#define data2_add 0x02
#define data3_add 0x03
#define data4_add 0x04
#define data5_add 0x05
#define data6_add 0x06
#define data7_add 0x07
#define data8_add 0x08
#define FMQ1 PORTC|=(1<<PORTC6)
#define FMQ0 PORTC&=~(1<<PORTC6)
void delay(uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=0;j<100;j++);
}
//***************************************************//
void write_7219(uchar add7219,uchar data7219)
{ uchar trdata,i=0,j;
LOAD7219_1();
delay(20);
LOAD7219_0();
delay(20);
CLK7219_0();
while(i<16)
{
if(i<8)
{ trdata=add7219;}
else
{ trdata=data7219;}
delay(20);
for(j=0;j<8;j++)
{
CLK7219_0();
delay(20);
if(trdata&0x80==0x80)
{DIN7219_1();}
else
{DIN7219_0();}
delay(20);
CLK7219_1();
delay(20);
trdata=trdata<<1;
}
i=i+8;
}
LOAD7219_1();
delay(20);
CLK7219_1();
}
/*
void write_7219(uchar add7219,uchar data7219)
{ uchar trdata,i=0,j;
LOAD7219_1();
LOAD7219_0();
while(i<2)
{
if(i<1)
trdata=add7219;
else
trdata=data7219;
CLK7219_0();
for(j=0;j<8;j++)
{
if(trdata&0x80==0x80)
DIN7219_1();
else
DIN7219_0();
// delay(5);
CLK7219_1();
trdata=trdata<<1;
CLK7219_0();
}
i=i++;
}
LOAD7219_1();
// delay(5);
}
*/
void ini_7219(void)
{
write_7219(stop_add,0x01);//正常显示 write_7219(stop_add,0x00) 关闭显示
delay(100);
write_7219(ceshi_add,0x00);//正常工作模式
delay(100);
write_7219(decode_add,0xff);//全部BCD译码
delay(100);
write_7219(bit_add,0x07);//扫描8位
delay(100);
write_7219(led_add,0x08);//亮度11/32
//write_7219(null_add,0x00);//空操作
//write_7219(ceshi_add,0x01);//全亮测试
}
void port_init(void)
{// DDR 0 为输入口 1 为输出口
// PORT DDR 为0时输入口时 PORT=1为上拉电阻使能,PORT=0时关闭
// DDR 为1时为输出口 PORT=1输出高电平,PORT=0输出低电平
//PORTA=0XFF;
//DDRA=0XFF;
//PORTB=0XFF;
//DDRB=0XFF;
PORTA = 0xFF; //高4位输出1,低4位上拉有效
DDRA = 0xF0; //高4位输出,地4位输入
PORTB = 0x07;
DDRB = 0x00;
//DDRC=0XFF;
//PORTC=0XFF;
//DDRD=0XFF;
//PORTD=0XFF;
DDRC = 0x7A;
PORTC = 0x03;
//pc1 load pd0 din pd1 clk 7219
//DDRC = 0x78;
DDRD = 0xE3;
PORTD = 0x1F;
//DDRD = 0xE0;
}
void init_devices(void)
{
CLI(); //禁止所有中断
MCUCR = 0x00;
//MCUCSR = 0x80;//禁止JTAG
GICR =0x00;
//MCUCR |= 0x02;//中断0 下降沿
//GICR |= 0x40;//外部中断0
//MCUCR |= 0x08;//中断1 下降沿
//GICR |= 0x80;//外部中断1
//MCUCSR|= 0x40;//中断1 上升沿
//GICR |= 0x20;//外部中断2
port_init();
}
void main(void)
{
//unsigned char p,k,s;
//uint i;
delay(1000);
init_devices();
//SEI();//开全局中断
ini_7219();
write_7219(0x01,1);
write_7219(0x02,2);
write_7219(0x03,3);
write_7219(0x04,4);
write_7219(0x05,5);
write_7219(0x06,6);
write_7219(0x07,7);
write_7219(0x08,8);
while(1)
{
//write_7219(0x01,1);
//write_7219(0x02,2);
//write_7219(0x03,3);
//write_7219(0x04,4);
//write_7219(0x05,5);
//write_7219(0x06,6);
//write_7219(0x07,7);
//write_7219(0x08,8);
//write_7219(ceshi_add,0x01);//全亮测试
//write_7219(ceshi_add,0x00);//正常工作模式
delay(20);
//FMQ1;
//PORTA=0XFF;
delay(1);
//FMQ0;
//PORTA=0X00;
}
}
|