本帖最后由 javastory 于 2021-5-13 16:36 编辑
我的问题是,给的数据是temp=0x7e,就是让点阵0和7列不亮,其他都亮,但是现在的现象是,在proteus里一步一步执行,每列导通的时候,行数据会变化2-3次,感觉是行、列数据不同步,但是printf输出的数据都是正确的数据。不知道问题在哪里,帮忙看看程序哪里错了吗?
8*8的点阵扫描代码,程序如下:
- #include <reg52.h>
- #include <intrins.h>
- #include <stdio.h>
- #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n)))
- #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n)))
- #define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n)))
- #define DEMCR (*((volatile unsigned long *)(0xE000EDFC)))
- #define TRCENA 0x01000000
- char putchar(char s)
- {
- SBUF=s;
- while(TI==0)
- {
- _nop_();
- }
- TI=0;
- }
- sbit ADDR0 = P2^0;
- sbit ADDR1 = P2^1;
- sbit ADDR2 = P2^2;
- sbit ADDR3 = P2^3;
- sbit COW_1641 = P0^0;
- //sbit COW_1642 = P0^2;
- sbit CLK_1641 = P0^1;
- sbit CLK_1642 = P0^3;
- sbit CLE_1641 = P0^2;
- unsigned char colcount[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
- unsigned char code image[8] = {0x00,0x00,0x7E,0x50,0x50,0x50,0x00,0x00};
- unsigned char i = 0; //动态扫描的索引
- unsigned int cnt = 0; //记录 T0 中断次数
- unsigned char flag1s = 0; //1 秒定时标志
- void delay(unsigned int delay){
- unsigned char i;
- for(;delay>0;delay--)
- for(i=0;i<150;i++);
- }
- void main(){
- unsigned long sec = 0; //记录经过的秒数
- EA = 1; //使能总中断
- CLE_1641 = 1;
- TMOD = 0x01; //设置 T0 为模式 1
- TH0 = 0xFC; //为 T0 赋初值 0xFC67,定时 1ms
- TL0 = 0x67;
- ET0 = 1; //使能 T0 中断
- TR0 = 1; //启动 T0
- while ( 1 ) {
-
- }
- }
- /* 定时器 0 中断服务函数 */
- void InterruptTimer0() interrupt 1 {
- unsigned int col,coldata,speed;
- unsigned char temp;
- TH0 = 0xFC; //重新加载初值
- TL0 = 0x67;
- cnt++; //中断次数计数值加 1
- if (cnt >= 1000) //中断 1000 次即 1 秒
- {
- cnt = 0; //清零计数值以重新开始下 1 秒计时
- flag1s = 1; //设置 1 秒定时标志为 1
- }
- //以下代码完成数码管动态扫描刷新
- for (col=0;col<8;col++){
- P2=col;
- //temp=image[col];
- temp=0x7E;
- printf("col = %u temp 1 = 0x%lX \n", col, temp);
- for(coldata=0;coldata<8;coldata++){
-
- printf("coldata = %u temp&0x80 = 0x%lX \n",coldata,temp);
- CLK_1641 = 0;
- COW_1641=temp&0x01;
- printf("coldata = %u COW_1641 = 0x%lX \n",coldata,COW_1641);
- CLK_1641 = 1;
- temp>>=1;
-
- printf("temp <<1 = 0x%lX \n",temp);
- }
- }
- }
复制代码
|