蓝桥杯错误记录

今天在做 小蜜蜂的综合案例的时候,数码管显示,有重影。

python 复制代码
#include <STC15F2K60S2.H>
unsigned char num;
unsigned char code Duan[22]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,
0xc6,0xc0,0x86,0x8e,0xbf,0x7f,0XC1,0X8C,0XC8,0xc3};
void shumadong();
void suocun(unsigned char n)
{
	switch(n)
	{
		case 4:P2 = (P2 & 0x1f)|0x80;break;
		case 5:P2 = (P2 & 0x1f)|0xa0;break;
		case 6:P2 = (P2 & 0x1f)|0xc0;break;
		case 7:P2 = (P2 & 0x1f)|0xe0;break;
	}
}

void shuma(unsigned char wei ,unsigned char shu)
{
	suocun(6);
	P0=0x01<<wei;
	suocun(7);
	P0=Duan[shu];
}
void Delay(unsigned int t)
{
while(t--);
}
void Delay_shuma(unsigned int t)
{
	while(t--)
	{
			shumadong();
	}
}
void shumadong()
{
	shuma(0,1);
	Delay(500);
	shuma(2,num);
	Delay(500);
	
}

void main()
{
	while(1)
	{
		shumadong();
		num+=1;
		if(num>9)
		{
			num=0;
		}
		Delay_shuma(100);
	}
}

原因是:在动态显示的函数里的延迟函数,我用了第二个在等待的时候扫描的延时。

这里的应该是消影,而第二个延迟函数在主函数里,加完num后,将他刷新。

python 复制代码
void Delay(unsigned int t)
{
while(t--);
}
void Delay_shuma(unsigned int t)
{
	while(t--)
	{
			shumadong();
	}
}
void shumadong()
{
	shuma(0,1);
	Delay(500);
	shuma(2,num);
	Delay(500);
	
}



在建立串口模块时,发生了,乱码行为。

python 复制代码
void init_chuan()
{
	TMOD = 0x20;
	AUXR = 0x00;
	SCON = 0x50;
	TH1 = 0xfd;
	TL1 = 0xfd;
	
	TR1=1;
	ES=1;
	EA=1;
}
void chuankou() interrupt 4
{
	if(RI==1)
	{
		data1=SBUF;
		RI=0;
	}
}
void working()
{
		if(data1 & 0xa0==0xa0)
		{
			if(data1 & 0x01 ==0x01)
			{
				L1=~L1;
			}
		}
}
void send(unsigned char dat)
{
	SBUF = dat;
	while(TI==0);
	TI=0;
}
void jv(unsigned char *p)
{
	while(*p !='\0')
	{
		send(*p++);
	}
}
void main()
{
	//suocun(4);
	//ding_Init();
	init_chuan();
	jv("we\r\n");
	while(1)
	{
		//shumadong();
		//jvzhen();
	}
}

最终原因是,我把串口的工作函数放在了中断里,如果放在中断里面,会一直判断。我又没发什么,所以会这样。



在建立串口模块时,我要发送0xa1来发送指令。

但是我每次发送以后,L1只亮,不灭。我设置的是L1=~L1。

找到原因是我在收到信息以后,没有将data1清零。

python 复制代码
void working()
{
		if(data1 & 0xa0==0xa0)
		{
			if(data1 & 0x01 ==0x01)
			{
				L1=~L1;
				send(data1);
				data1=0x00;
			}
		}
}
相关推荐
qq_459234424 天前
【题库】| 商用密码应用安全性评估从业人员考核题库(四十)
职场和发展·密码学·学习方法·考核·商用密码·商用密码应用安全性评估·密评
敲敲了个代码4 天前
[特殊字符] 空数组的迷惑行为:为什么 every 为真,some 为假?
前端·javascript·react.js·面试·职场和发展
诚思报告YH4 天前
视频面试软件市场洞察:2026 - 2032年复合年均增长率(CAGR)为10.3%
面试·职场和发展
重生之后端学习4 天前
74. 搜索二维矩阵
开发语言·数据结构·算法·职场和发展·深度优先
tyb3333334 天前
leetcode:吃苹果和队列
算法·leetcode·职场和发展
Pitiless-invader4 天前
MySQL 相关知识及面试问题汇总
面试·职场和发展
重生之后端学习4 天前
35. 搜索插入位置
java·数据结构·算法·leetcode·职场和发展·深度优先
逆境不可逃4 天前
【从零入门23种设计模式08】结构型之组合模式(含电商业务场景)
线性代数·算法·设计模式·职场和发展·矩阵·组合模式
筱昕~呀4 天前
冲刺蓝桥杯-DFS板块(第二天)
算法·蓝桥杯·深度优先
zheshiyangyang4 天前
前端面试基础知识整理【Day-10】
前端·面试·职场和发展