钻石会员
主题
帖子
积分11460
阅读权限50
注册时间2008-12-31
最后登录1970-1-1
在线时间 小时
|
本帖最后由 gw168sh 于 2012-9-11 07:57 编辑
用的STMS103F2,因数码管不在一个P口,要组到一起用。
但是显示会乱。还好现在知道一点规律了,请教一下论坛的朋友。
1。我试过,只让某一为显示,且这个数字不变的情况下显示正常。 如给数赋值1,只让个位显示就正常。(0-9都可以)
2.只扫描一位,如个位,如果让shu++; 1.2.正常后面就乱了套了。
3.如果扫描4位,shu=1234;不变。四位一样乱套。
昨夜折腾1.30没找到问题,郁闷的很
- /* MAIN.C file
- *
- * Copyright (c) 2002-2005 STMicroelectronics
- */
- #include <iostm8a.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define GE_ON PD_ODR&=0b11101111;//PD4输出0
- #define GE_OFF PD_ODR|=0b00010000;//PD4输出1
- #define SHI_ON PD_ODR&=0b11011111;//PD5输出0
- #define SHI_OFF PD_ODR|=0b00100000;//PD5输出1
- #define BAI_ON PD_ODR&=0b10111111;//PD6输出0
- #define BAI_OFF PD_ODR|=0b01000000;//PD6输出1
- #define QIAN_ON PA_ODR&=0b11110111;//PA3为输出0
- #define QIAN_OFF PA_ODR|=0b00001000;//PA3为输出1
- uint shu,num;
- const uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
- 0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- //const uchar table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,
- //0xF8,0x80,0x90};//共阳0-9的LED笔划
- void LED_7(unsigned char da)
- {
- uchar Px7,Px6,Px5,Px4,Px3,Px2,Px1,Px0;
- //Px7 = (da&0x80); //H---
- // if(Px7==1) ;
- //else if(Px7==0) ;
- Px6 = (da&0x40); //G---
- if(Px6==1) PC_ODR&=0b11110111;//PC3为输出0
- else if(Px6==0) PC_ODR|=0b00001000;//PC3为输出1
- Px5 = (da&0x20); //F
- if(Px5==1) PC_ODR&=0b11101111;//PC4为输出0
- else if(Px5==0) PC_ODR|=0b00010000;//PC4为输出1
- Px4 = (da&0x10); //E
- if(Px4==1) PC_ODR&=0b11011111;//PC5为输出0
- else if(Px4==0) PC_ODR|=0b00100000;//PC5为输出1
- Px3 = (da&0x08); //D
- if(Px3==1) PC_ODR&=0b10111111;//PC6为输出0
- else if(Px3==0) PC_ODR|=0b01000000;//PC6为输出1
- Px2 = (da&0x04); //C
- if(Px2==1) PC_ODR&=0b01111111;//PC7为输出0
- else if(Px2==0) PC_ODR|=0b10000000;//PC7为输出1
- Px1 = (da&0x02); //B
- if(Px1==1) PD_ODR&=0b11111101;//PD1为输出0
- else if(Px1==0) PD_ODR|=0b00000010;//PD1为输出1
- Px0 = (da&0x01); //A
- if(Px0==1) PD_ODR&=0b11111011;//PD2为输出0
- else if(Px0==0) PD_ODR|=0b00000100;//PD2为输出1
- }
- void GPIO_Init(void)
- {
- PD_DDR|=0b11110111;//PD为输出,
- PD_CR1|=0b11110111;//对应位设置为推挽输出
- PC_DDR|=0b11111111;//PC为输出,
- PC_CR1|=0b11111111;//对应位设置为推挽输出
- PA_DDR|=0b00001111;//PA为输出,
- PA_CR1|=0b00001111;//对应位设置为推挽输出
- //PD_CR1&=0xF2;//对应位设置为模拟开漏输出(不是真正开漏)
- }
- void Delay(unsigned int i)
- {
- unsigned int j;
- while(i--)
- {
- //for(j=0;j<10000;j++);
- }
- }
- main()
- {
- GPIO_Init();
- shu=0;
- while (1)
- {
- uchar a1,a2,a3,a4;
- a4=shu/1000;
- a3=shu%1000/100;
- a2=shu%100/10;
- a1=shu%10;
- num++;
- if(num==300)
- {
- num=0;
- shu++;
- }
- //LED_7(table[a1]); GE_ON; Delay(1000); GE_OFF;
- //LED_7(table[a2]); SHI_ON; Delay(1000); SHI_OFF;
- //LED_7(table[a3]); BAI_ON; Delay(1000); BAI_OFF;
- //LED_7(table[a4]); QIAN_ON; Delay(1000); QIAN_OFF;
- LED_7(table[a1]); GE_OFF; Delay(1000); GE_ON; Delay(100);
- //LED_7(table[a2]); SHI_OFF; Delay(1000); SHI_ON; Delay(100);
- //LED_7(table[a3]); BAI_OFF; Delay(1000); BAI_ON; Delay(100);
- //LED_7(table[a4]); QIAN_OFF; Delay(1000); QIAN_ON; Delay(100);
- }
- }
复制代码 |
|