|
|
本菜雞大三,目前在做單片機設計,三個課題,其中一個是實現路口紅綠燈,但是我遇到的問題是我的數碼管顯示不正常,現象是開始仿真后看不見數碼管顯示的數字,只有按下暫停才會顯示代碼我也沒找到問題,數碼管采用共陽極接法,在proteus中的型號名稱為7SEG-MPX8-CA,第一個圖片就可以看作是proteus開始仿真的實時效果,,第二個圖片是按下暫停時的效果,關于數碼管部分我想達到的效果是第三個圖里數字時鐘的那種顯示效果,關于數碼管顯示的代碼如下,求大佬指點一二,
#include <regx52.h>
#include <INTRINS.H>
#include "tim.h"
void delay(uchar xms);
void shumashow(uchar location,uchar number);
void display();
void displays(void);
uchar button=0;
uchar code shuma[10]={0x88,0xbb,0xc1,0x91,0xb2,0x94,0x04,0xb9,0x80,0x90};
void main(){
while(1){
displays();
}
}
/*
數碼管顯示
*/
void displays(void){
shumashow(1,1);delay(1);
shumashow(2,2);delay(1);
shumashow(3,3);delay(1);
shumashow(4,4);delay(1);
shumashow(5,5);delay(1);
shumashow(6,6);delay(1);
shumashow(7,7);delay(1);
shumashow(8,8);delay(1);
}
void shumashow(uchar location,uchar number){
switch(location){
case 1: P1_0=0; P1_1=0;P1_2=0;break;
case 2: P1_0=0; P1_1=0;P1_2=1;break;
case 3: P1_0=0; P1_1=1;P1_2=0;break;
case 4: P1_0=0; P1_1=1;P1_2=1;break;
case 5: P1_0=1; P1_1=0;P1_2=0;break;
case 6: P1_0=1; P1_1=0;P1_2=1;break;
case 7: P1_0=1; P1_1=1;P1_2=0;break;
case 8: P1_0=1; P1_1=1;P1_2=1;break;
}
P0=shuma[number];
}
void delay(uchar xms){
uchar i,j;
while(xms){
i=2;
j=239;
do{
while(--j);
}while(--i);
xms--;
}
}
|
|