AVR单片机大神看看下面这个CH451驱动的程序,为什么我这么写数码管不亮?
#include<iom64v.h>#include<macros.h>#include"DELAY_8M.h"unsignedcharCH451_SEG,CH451_C...
#include<iom64v.h>#include<macros.h>#include"DELAY_8M.h"
unsigned char CH451_SEG,CH451_CMD,DIG[6];
const unsigned char S[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//CH451显示芯片引脚定义
//**DCLK:PORTA0,DIN:PORTA1,LOAD:PORTA2,DOUT:PORTA3
#define CH451DCLK_1 PORTB |= BIT(2) //DCLK=1
#define CH451DCLK_0 PORTB &=~ BIT(2) //DCLK=0
#define CH451DIN_1 PORTB |= BIT(3)
#define CH451DIN_0 PORTB &=~ BIT(3)
#define CH451LOAD_1 PORTB |= BIT(4)
#define CH451LOAD_0 PORTB &=~BIT(4)
#define CH451DOUT_1 PORTB |= BIT(5)
#define CH451DOUT_0 PORTB &=~BIT(5)
void CH451_WRITE(void)
{
unsigned int i;
CH451_LOAD_0; //LOAD=0
for (i=1;i<=0x80;i=i<<1){ //读数据
CH451_DCLK_0; //DCLK的上升沿将DIN的数据移入移位寄存器
if (CH451_SEG&i)
CH451_DIN_1; //DIN=1
else
CH451_DIN_0; //DIN=0
CH451_DCLK_1; //DIN移入移位寄存器 低位在前
}/*end for(i=1;i<=0x80;i=i<<1)*/
for (i=1;i<=0x80;i=i<<1){ //读指令
CH451_DCLK_0; //DCLK的上升沿将DIN的数据移入移位寄存器
if (CH451_CMD&i)
CH451_DIN_1; //DIN=1
else
CH451_DIN_0; //DIN=0
CH451_DCLK_1; //DIN移入移位寄存器 低位在前
}/*end for(i=1;i<=0x80;i=i<<1)*/
CH451_LOAD_1;
}
void CH451_Init(void)
{
PORTB&=~0x08;//DIN先低后高上升沿通知CH451使能4线串行口
PORTB|=0x04;//DCLK置为默认的高电平
PORTB|=0x08;//DIN
PORTB|=0x10;//LOAD
CH451_CMD=0x04; //设置系统参数
CH451_SEG=0x03;
CH451_WRITE();
CH451_CMD=0x05; //设置显示参数
CH451_SEG=0x00;
CH451_WRITE();
}
int main(void)
{
unsigned int i,j;
port_Init();
CH451_Init();
while(1){
for (i=0;i<7;i++){
CH451_CMD = 0X08+i;
DIG[0] = S[i];
CH451_WRITE();
}
CH451_CMD = 0X06;
CH451_SEG = 0X00;
CH451_WRITE();
}
return 0; }
上面主函数写错了,主函数是这样的。我想实现6个数码管同时显示0-9,这样写数码管亮都不亮,为什么?
int main(void)
{
unsigned int i,j;
port_Init();
CH451_Init();
while(1){
for(j=0;j<10;j++){
DIG[0] = S[j];
DIG[1] = S[j];
DIG[2] = S[j];
DIG[3] = S[j];
DIG[4] = S[j];
DIG[5] = S[j];
for (i=0;i<7;i++){
CH451_CMD = 0X08+i;
CH451_SEG = DIG[i];
CH451_WRITE();
}
CH451_CMD = 0X06;
CH451_SEG = 0X00;
CH451_WRITE();
delay8M_xus(1000);
}
}
return 0; } 展开
unsigned char CH451_SEG,CH451_CMD,DIG[6];
const unsigned char S[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//CH451显示芯片引脚定义
//**DCLK:PORTA0,DIN:PORTA1,LOAD:PORTA2,DOUT:PORTA3
#define CH451DCLK_1 PORTB |= BIT(2) //DCLK=1
#define CH451DCLK_0 PORTB &=~ BIT(2) //DCLK=0
#define CH451DIN_1 PORTB |= BIT(3)
#define CH451DIN_0 PORTB &=~ BIT(3)
#define CH451LOAD_1 PORTB |= BIT(4)
#define CH451LOAD_0 PORTB &=~BIT(4)
#define CH451DOUT_1 PORTB |= BIT(5)
#define CH451DOUT_0 PORTB &=~BIT(5)
void CH451_WRITE(void)
{
unsigned int i;
CH451_LOAD_0; //LOAD=0
for (i=1;i<=0x80;i=i<<1){ //读数据
CH451_DCLK_0; //DCLK的上升沿将DIN的数据移入移位寄存器
if (CH451_SEG&i)
CH451_DIN_1; //DIN=1
else
CH451_DIN_0; //DIN=0
CH451_DCLK_1; //DIN移入移位寄存器 低位在前
}/*end for(i=1;i<=0x80;i=i<<1)*/
for (i=1;i<=0x80;i=i<<1){ //读指令
CH451_DCLK_0; //DCLK的上升沿将DIN的数据移入移位寄存器
if (CH451_CMD&i)
CH451_DIN_1; //DIN=1
else
CH451_DIN_0; //DIN=0
CH451_DCLK_1; //DIN移入移位寄存器 低位在前
}/*end for(i=1;i<=0x80;i=i<<1)*/
CH451_LOAD_1;
}
void CH451_Init(void)
{
PORTB&=~0x08;//DIN先低后高上升沿通知CH451使能4线串行口
PORTB|=0x04;//DCLK置为默认的高电平
PORTB|=0x08;//DIN
PORTB|=0x10;//LOAD
CH451_CMD=0x04; //设置系统参数
CH451_SEG=0x03;
CH451_WRITE();
CH451_CMD=0x05; //设置显示参数
CH451_SEG=0x00;
CH451_WRITE();
}
int main(void)
{
unsigned int i,j;
port_Init();
CH451_Init();
while(1){
for (i=0;i<7;i++){
CH451_CMD = 0X08+i;
DIG[0] = S[i];
CH451_WRITE();
}
CH451_CMD = 0X06;
CH451_SEG = 0X00;
CH451_WRITE();
}
return 0; }
上面主函数写错了,主函数是这样的。我想实现6个数码管同时显示0-9,这样写数码管亮都不亮,为什么?
int main(void)
{
unsigned int i,j;
port_Init();
CH451_Init();
while(1){
for(j=0;j<10;j++){
DIG[0] = S[j];
DIG[1] = S[j];
DIG[2] = S[j];
DIG[3] = S[j];
DIG[4] = S[j];
DIG[5] = S[j];
for (i=0;i<7;i++){
CH451_CMD = 0X08+i;
CH451_SEG = DIG[i];
CH451_WRITE();
}
CH451_CMD = 0X06;
CH451_SEG = 0X00;
CH451_WRITE();
delay8M_xus(1000);
}
}
return 0; } 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询