完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
使用SH79F166A做上位机控制TM1629B显示LED,数码管计数显示。但是该板写入0X00,或者使用关显示0x80都无法使之熄灭。同时,LED是乱显示的。一个个地址地试也无法得到想要的结果,做不到单个LED单独亮灭,代码如下(请自动忽略其中的触摸按键函数):
#define.h #ifndef _DEFINE_H #define _DEFINE_H #include #include typedef unsigned char uint8; typedef signed char int8; typedef unsigned int uint16; typedef signed int int16; #define NOP _nop_() #define Mode_Auto 0x40 #define Mode_Manual 0x44 #define Mode_Disp 0x8F #define Read_Key 0x42 #define Disp_Off 0x80 #define Start_Addr 0xC0 #define Power_heart 0xC1 #define Set_fan 0xC3 #define UP_SW_time 0xC5 #define Warm_DOWN 0xC7 #define HUICHA_Time 0xC8 #define Temp_AddrH 0xCF #define Temp_AddrL 0xCD #define Time_HourH 0xC5 #define Time_HourL 0xC6 #define Time_MinuH 0xCA #define Time_MinuL 0xCB #define zero 0x3F #define S_F_LED_OFF 0x08 #define P_H_LED_OFF 0x40 #define Key_ON 0x10 #define Heart_ON 0x02 #define All 0x02 #define ttt 0x10 ***it DIO=P3^2; ***it CLK=P4^2; ***it STB=P1^6; //***it TDI=P1^5; //***it TCK=P1^4; void LedInit(); uint8 KeyScan(); //void I2CInit(); void I2CStop(); void I2CStart(); void Timer2Init(); uint8 I2CReadData(); void DisplayTemp(); void DisplayTime(); uint8 LedReadData(); uint8 I2CReadData(); void ReadUartInit(); void Delay(uint8 t); void WriteUartInit(); void delayus(uint8 t); void Display(uint8 Data); void DisplayKey(uint8 Key); void I2CWriteData(uint8 Data); void LedWriteData(uint8 Data); void DisplayFunction(uint8 Function); #endif #main.c #include"define.h" extern uint8 FlagTime; void main() { // uint8 i; P3CR=0xff; P3PCR=0x0; P3=0x00; P4CR=0xff; P4PCR=0x0; P4=0x00; P1CR=0xff; P1PCR=0x0; P1=0x00; Timer2Init(); LedInit(); Display(Disp_Off); while(1) { Display(All); // DisplayTemp(); // DisplayTime(); // Delay(1); } } void Timer2Init() { T2CON=0x00; T2MOD=0x00; RCAP2H=(65536-50000)/256; RCAP2L=(65536-50000)%256; TH2=(65536-50000)/256; TL2=(65536-50000)%256; IEN0|=0xa0; EA=1; ET2=1; TR2=1; TF2=0; } void timer2() interrupt 5 //5ms自动重载定时器 { static uint8 t; t++; TF2=0; if(t>=10) { FlagTime=1; t=0; } // KeyScan(); } void Delay(uint8 t) { uint8 i,j; for(;t>0;t--) { for(i=0;i<255;i++) { for(j=0;j<255;j++); } } } #led.c #include"define.h" uint8 code digit[]={ 0x3F,0x30,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F }; uint8 FlagTime=0; uint8 time=0; void LedInit() { CLK=1; DIO=1; STB=1; } void LedWriteData(uint8 Data) { uint8 i; STB=0; for(i=0;i<8;i++) { CLK=0; if((Data&0x01)==0x01) { DIO=1; }else { DIO=0; } CLK=1; NOP;NOP;NOP;NOP;NOP; Data=Data>>1; NOP;NOP;NOP; } } uint8 LedReadData() { uint8 i; uint8 ReadData; CLK=0; DIO=1; for(i=0;i<8;i++) { CLK=1; //上升沿读数据 ReadData=ReadData>>1; if(DIO==0x01) { ReadData|=0x80; } else{ ReadData&=0x7F; } CLK=0; NOP;NOP;NOP; } DIO=1; return ReadData; } void Display(uint8 Data) { uint8 i; LedWriteData(Mode_Manual); STB=1; LedWriteData(Start_Addr); // for(i=0;i<1;i++) // { LedWriteData(Data); // } STB=1; LedWriteData(Mode_Disp); STB=1; } void DisplayTime() { LedWriteData(Mode_Manual); if(FlagTime==1) { time++; FlagTime=0; } if(time>=0) { STB=1; LedWriteData(Time_HourH); LedWriteData(digit[time/60/10]); STB=1; LedWriteData(Time_HourL); LedWriteData(digit[time/60%10]); STB=1; LedWriteData(Time_MinuH); LedWriteData(digit[time%60/10]); STB=1; LedWriteData(Time_MinuL); LedWriteData(digit[time%60%10]); STB=1; LedWriteData(Mode_Disp); STB=1; } if(time==1440) { time=0; } } void DisplayTemp() { uint8 i; LedWriteData(Mode_Manual); for(i=0;i<60;i++) { STB=1; LedWriteData(Temp_AddrH); LedWriteData(digit[i/10]); STB=1; LedWriteData(Temp_AddrL); LedWriteData(digit[i%10]); STB=1; LedWriteData(Mode_Disp); STB=1; Delay(1); } } |
|
相关推荐
3个回答
|
|
配置有问题哦
最佳答案
|
|
|
|
整了一天,问题终于解决了,原来在采用自动地址加一的方式循环中,不知道什么时候把16的6给删了,导致,地址一直处于起始地址。此外,由于换了块板,新板的LED屏引脚有错误,数码管的段码不是处于同一个地址中,每个8中的一横都在上一个地址中,就很蛋疼,找了半天才找出来,同时导致原来的数字编码失效,需要重新推出新的数字编码。在一个个地尝试之后,终于实现了LED的计时显示和温度度数显示。。。接下来就等着触摸IC供应商上门指导触摸编程啦~~
代码如下(请自动忽略触摸部分) #define.h #ifndef _DEFINE_H #define _DEFINE_H #include #include typedef unsigned char uint8; typedef signed char int8; typedef unsigned int uint16; typedef signed int int16; #define NOP _nop_() #define Mode_Auto 0x40 #define Mode_Manual 0x44 #define Mode_Disp 0x8F #define Disp_Off 0x80 #define Start_Addr 0xC0 #define Temp_Hevel 0xCC #define Temp_Level 0xCE #define Temp_AddrH 0xCD #define Temp_AddrL 0xCF #define Time_HourH 0xC5 #define Time_HourL 0xC7 #define Time_MinuH 0xC9 #define Time_MinuL 0xCB #define Time_HHevel 0xC4 #define Time_HLevel 0xC6 #define Time_LHevel 0xC8 #define Time_LLevel 0xCA #define All 0x00 #define ttt 0x01 ***it DIO=P3^2; ***it CLK=P4^2; ***it STB=P1^6; //***it TDI=P1^5; //***it TCK=P1^4; void LedInit(); uint8 KeyScan(); //void I2CInit(); void I2CStop(); void I2CStart(); void Timer2Init(); uint8 I2CReadData(); void DisplayTemp(); void DisplayTime(); uint8 LedReadData(); uint8 I2CReadData(); void ReadUartInit(); void Delay(uint8 t); void WriteUartInit(); void delayus(uint8 t); void Display(uint8 Data); void DisplayKey(uint8 Key); void I2CWriteData(uint8 Data); void LedWriteData(uint8 Data); void DisplayFunction(uint8 Function); #endif main.c #include"define.h" extern uint8 FlagTime; void main() { // uint8 i; P3CR=0xff; P3PCR=0x0; P3=0x00; P4CR=0xff; P4PCR=0x0; P4=0x00; P1CR=0xff; P1PCR=0x0; P1=0x00; Timer2Init(); LedInit(); Display(All); while(1) { // DisplayTemp(); DisplayTime(); // Delay(1); } } void Timer2Init() { T2CON=0x00; T2MOD=0x00; RCAP2H=(65536-50000)/256; RCAP2L=(65536-50000)%256; TH2=(65536-50000)/256; TL2=(65536-50000)%256; IEN0|=0xa0; EA=1; ET2=1; TR2=1; TF2=0; } void timer2() interrupt 5 //5ms自动重载定时器 { static uint8 t; t++; TF2=0; if(t>=10) { FlagTime=1; t=0; } // KeyScan(); } void Delay(uint8 t) { uint8 i,j; for(;t>0;t--) { for(i=0;i<255;i++) { for(j=0;j<255;j++); } } } led.c #include"define.h" uint8 code digit[]={ 0x3F,0x03,0xB6,0xBC,0x99,0xAD,0xAF,0x38,0xBF,0xBD }; uint8 FlagTime=0; uint8 time=0; void LedInit() { CLK=1; DIO=1; STB=1; } void LedWriteData(uint8 Data) { uint8 i; STB=0; for(i=0;i<8;i++) { CLK=0; if((Data&0x01)==0x01) { DIO=1; }else { DIO=0; } CLK=1; NOP;NOP;NOP;NOP;NOP; Data=Data>>1; NOP;NOP;NOP; } } uint8 LedReadData() { uint8 i; uint8 ReadData; CLK=0; DIO=1; for(i=0;i<8;i++) { CLK=1; //上升沿读数据 ReadData=ReadData>>1; if(DIO==0x01) { ReadData|=0x80; } else{ ReadData&=0x7F; } CLK=0; NOP;NOP;NOP; } DIO=1; return ReadData; } void Display(uint8 Data) { uint8 i; LedWriteData(Mode_Auto); STB=1; LedWriteData(Start_Addr); for(i=0;i<16;i++) { LedWriteData(Data); } STB=1; LedWriteData(Mode_Disp); STB=1; } void DisplayTime() { LedWriteData(Mode_Manual); if(FlagTime==1) { time++; FlagTime=0; } if(time>=0) { if(((time/60/10)==0)||((time/60/10)==1)||((time/60/10)==7)) { STB=1; LedWriteData(Time_HHevel); LedWriteData(0x00); } else { STB=1; LedWriteData(Time_HHevel); LedWriteData(0x80); } if(((time/60%10)==0)||((time/60%10)==1)||((time/60%10)==7)) { STB=1; LedWriteData(Time_HLevel); LedWriteData(0x00); } else { STB=1; LedWriteData(Time_HLevel); LedWriteData(0x80); } if(((time%60/10)==0)||((time%60/10)==1)||((time%60/10)==7)) { STB=1; LedWriteData(Time_LHevel); LedWriteData(0x00); } else { STB=1; LedWriteData(Time_LHevel); LedWriteData(0x80); } if(((time%60%10)==0)||((time%60%10)==1)||((time%60%10)==7)) { STB=1; LedWriteData(Time_LLevel); LedWriteData(0x00); } else { STB=1; LedWriteData(Time_LLevel); LedWriteData(0x80); } STB=1; LedWriteData(Time_HourH); LedWriteData(digit[time/60/10]); STB=1; LedWriteData(Time_HourL); LedWriteData(digit[time/60%10]); STB=1; LedWriteData(Time_MinuH); LedWriteData(digit[time%60/10]); STB=1; LedWriteData(Time_MinuL); LedWriteData(digit[time%60%10]); STB=1; LedWriteData(Mode_Disp); STB=1; } if(time==1440) { time=0; } } void DisplayTemp() { uint8 i; LedWriteData(Mode_Auto); for(i=0;i<60;i++) { if(((i/10)==0)||((i/10)==1)||((i/10)==7)) { STB=1; LedWriteData(Temp_Hevel); LedWriteData(0x00); }else { STB=1; LedWriteData(Temp_Hevel); LedWriteData(0x80); } if(((i%10)==0)||((i%10)==1)||((i%10)==7)) { STB=1; LedWriteData(Temp_Level); LedWriteData(0x00); }else { STB=1; LedWriteData(Temp_Level); LedWriteData(0x80); } STB=1; LedWriteData(Temp_AddrH); LedWriteData(digit[i/10]); STB=1; LedWriteData(Temp_AddrL); LedWriteData(digit[i%10]); STB=1; LedWriteData(Mode_Disp); STB=1; Delay(1); } } |
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
464 浏览 0 评论
478 浏览 1 评论
基于瑞萨FPB-RA4E2智能床头灯项目——1编译环境搭建与点亮驱动ws2812全彩LED
439 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
994 浏览 0 评论
《DNESP32S3使用指南-IDF版_V1.6》第二章 常用的C语言知识点
1056 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11780 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 02:50 , Processed in 0.506438 second(s), Total 49, Slave 41 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号