通宵整晚都没停销过,一直在专注的焊板子。。。
很喜欢这种感觉!
谁叫我是电子爱好者呢~
#include <reg52.h>
unsigned char code seg[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,0xff,0x00,0,0x55,0x55,0xaa,0xaa};
void delay(unsigned int cnt)
{
while(--cnt);
}
main()
{
unsigned char i;
while(1)
{
P1=0xFE;
for(i=0;i<8;i++)
{
delay(10000);
P1 <<=1;
}
P1=0x7F;
for(i=0;i<8;i++)
{
delay(10000);
P1 >>=1;
}
P1=0xFE;
for(i=0;i<8;i++)
{
delay(10000);
P1 <<=1;
P1 |=0x01;
}
P1=0x7F;
for(i=0;i<8;i++)
{
delay(10000);
P1 >>=1;
P1 |=0x80;
}
for(i=0;i<16;i++)
{
delay(20000);
P1=seg[i];
}
}
}
驱动1602液晶代码:
#include<reg52.h>
#include<stdio.h>
#include<intrins.h>
sbit RS = P2^4;
sbit RW = P2^5;
sbit E = P2^6;
#define Data P0
char data TimeNum[]=" ";
char data Test1[]=" ";
void DelayUs(unsigned char us)
{
unsigned char uscnt;
uscnt=us>>1;
while(--uscnt);
}
void DelayMs(unsigned char ms)
{
while(--ms)
{
DelayUs(250);
DelayUs(250);
DelayUs(250);
DelayUs(250);
}
}
void WriteCommand(unsigned char c)
{
DelayMs(5);
E=0;
RS=0;
RW=0;
_nop_();
E=1;
Data=c;
E=0;
}
void WriteData(unsigned char c)
{
DelayMs(5);
E=0;
RS=1;
RW=0;
_nop_();
E=1;
Data=c;
E=0;
RS=0;
}
void ShowChar(unsigned char pos,unsigned char c)
{
unsigned char p;
if (pos>=0x10)
p=pos+0xb0;
else
p=pos+0x80;
WriteCommand (p);
WriteData (c);
}
void ShowString (unsigned char line,char *ptr)
{
unsigned char l,i;
l=line<<4;
for (i=0;i<16;i++)
ShowChar (l++,*(ptr+i));
}
void InitLcd()
{
DelayMs(15);
WriteCommand(0x38);
WriteCommand(0x38);
WriteCommand(0x38);
WriteCommand(0x06);
WriteCommand(0x0c);
WriteCommand(0x01);
}
void main(void)
{
InitLcd();
DelayMs(15);
sprintf(Test1,"www.eepw.com.cn ");
ShowString(0,Test1);
sprintf(TimeNum,"583199723MCU DIY");
ShowString(1,TimeNum);
while(1);
}
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 | |
【FRDM-MCXN947评测】核间通信MUTEX被打赏50分 |