完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include"STC12C5A.h"
void keyscan();void find(unsigned char num);void process(); unsigned char keynum=0; unsigned char const seg[10] = {0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6}; //段选 ***it HC595_SCK = P0^4;***it HC595_RCK = P0^5;***it HC595_RST = P0^6;***it HC595_DAT = P0^7; void sendbyte(unsigned char num); void show(unsigned char num); void diaplay(unsigned char num); void delay_ms(unsigned char time); void main(){ P0 &=~(1<<6); while(1){ keyscan(); process(); } } void delay_ms(unsigned char time){ unsigned char t; while(time--) { t=1500; while(t--); }} void diaplay(unsigned char num) { show(num/1000); 0 = (P0&0xf0)|1; delay_ms(2); show(num%1000/100); 0 = (P0&0xf0)|2; //数码管位选 delay_ms(2); show(num%1000/100); 0 = (P0&0xf0)|4; delay_ms(2); show(num%1000/100); 0 = (P0&0xf0)|8; delay_ms(2); } void show(unsigned char num){ sendbyte(seg[num]);} void sendbyte(unsigned char num){ unsigned char i,temp; for(i=0;i<=7;i++) { temp = num&1< void find(unsigned char num){ keynum=0; 2=0X0F; switch((~P2)&0X0F) { case 1: keynum=1+num;break;case 2: keynum=4+num;break;case 4: keynum=8+num;break;case 8: keynum=12+num;break;default: break; }} void keyscan(){ 2=0X80; //将p2^7置高电平,若p2^7不再为高电平,说明这一列有按键按下 if(P2&0X80!=0X80) { delay_ms(15); if(P2&0X80!=0X80) find(0); } 2=0X40; if(P2&0X40!=0X40) { delay_ms(15); if(P2&0X40!=0X40) find(4); } 2=0X20; if(P2&0X20!=0X20) { delay_ms(15); if(P2&0X20!=0X20) find(8); } 2=0X10; if(P2&0X10!=0X10) { delay_ms(15); if(P2&0X10!=0X10) find(12); }} void process() { switch(process) { case 1: show(1);break; case 2: show(2);break; case 3: show(3);break; case 4: show(4);break; case 5: show(5);break; case 6: show(6);break; case 7: show(7);break; case 8: show(8);break; case 9: show(9);break; case 10: show(10);break; case 11: show(11);break; case 12: show(12);break; case 13: show(13);break; case 14: show(14);break; case 15: show(15);break; case 16: show(16);break; } } 单片机型号是STC12C5A60S2,4位数码管,就是想扫描矩阵键盘,但数码管显示的不知道什么东西 求解答!!! |
|
相关推荐
6个回答
|
|
|
|
|
|
|
|
|
|
先搞定数码管显示,数码管显示正常了,再做按键扫描测试。
|
|
|
|
数码管是正常的啊,我刚写一个动态显示,完全正常,只是扫面不知道出了什么问题
|
|
|
|
#include"STC12C5A.h"
unsigned char reg[10]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6}; ***it smg_sck = P0^4;***it smg_rck = P0^5;***it smg_rst = P0^6;***it smg_dat = P0^7; void delay_ms(unsigned char time){ unsigned char t; while(time--) { t=1500; while(t--); }} void sendbyte(unsigned char byte){ unsigned char i;for( i=0;i<8;i++){ unsigned char temp; temp=byte&(1< void show(unsigned char num){ sendbyte(reg[num]);} void display(unsigned char dat){ show(dat/1000);P0=(P0&0XF0)|1;delay_ms(2); show(dat%1000/100);P0=P0&0XF0|2;delay_ms(2); show(dat%100/10);P0=P0&0XF04|4;delay_ms(2); show(dat%10);P0=P0&0XF0|8;delay_ms(2);} void main (){ while(1) { unsigned char time,num=0; P0=0X00; smg_rst=0; while(1) {num = (num+1)%10000;//动态显示0~9999time = 2;while(time--)display(num) ;} } } 最后数码管只显示到250,怎么回事? |
|
|
|
|
|
只有小组成员才能发言,加入小组>>
3319 浏览 9 评论
2997 浏览 16 评论
3495 浏览 1 评论
9065 浏览 16 评论
4088 浏览 18 评论
1185浏览 3评论
611浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
601浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2337浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1897浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 17:23 , Processed in 1.506464 second(s), Total 92, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号