最近发现Proteus里面也可以做ARM的仿真,不过只支持ARM7,手头又刚好有LPC2106的书,就顺便做了个1602液晶的仿真,感觉不错!
源代码如下:
#include "config.h"
#define LCM_RS (1<<8)
#define LCM_RW (1<<9)
#define LCM_EN (1<<10)
#define LCM_BUSY (1<<7)
uint8 txt[]="Hi, Craftor!";
void delay(uint16 dly)
{
uint16 i;
while(--dly)
for (i=0;i<5000;i++);
}
void chkbusy()
{
IODIR = 0x700;
while(1)
{
IOCLR = LCM_RS;
IOSET = LCM_RW;
IOSET = LCM_EN;
if (!(IOPIN & LCM_BUSY)) break;
IOCLR = LCM_EN;
}
IODIR = 0x7ff;
}
void write_cmd(uint8 dat)
{
chkbusy();
IOCLR = LCM_RS;
IOCLR = LCM_RW;
IOCLR = 0xff;
IOSET = dat;
IOSET = LCM_EN;
delay(2);
IOCLR = LCM_EN;
}
void write_dat(uint8 dat)
{
chkbusy();
IOSET = LCM_RS;
IOCLR = LCM_RW;
IOCLR = 0xff;
IOSET = dat;
IOSET = LCM_EN;
delay(2);
IOCLR = LCM_EN;
}
void lcm_init()
{
write_cmd(0x38);
write_cmd(0x06);
write_cmd(0x0f);
}
void dis_txt(uint16 addr, uint8 *p)
{
write_cmd(addr);
while(*p != '\0')
write_dat(*(p++));
}
int main(void)
{
lcm_init();
IODIR = 0x7ff;
IOCLR = 0x7ff;
dis_txt(0x80,txt);
while(1);
}
文章评论(0条评论)
登录后参与讨论