我在做这个仿真的时候也遇到了一定问题,现附上proteus仿真模拟图和源代码供大家参考。大家在用这块屏幕取字模的时候一定要注意是行列式还是列行试。注意在打印数组的时候要注意他的页与行的变换。加油
仿真原理图如下
单片机源程序如下:
#include "sys.h"
#include "usart.h"
#include "delay.h"
//unsigned char a[10]="mengxinyu";
unsigned char a[]={//孟
/* 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e
省略
0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x03,0x02,0x02,0x00,0x00,/*"?",2*/
};
void LCD_Init(void)
{
/*GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_WriteBit(GPIOB,GPIO_Pin_6,0) ;
GPIO_WriteBit(GPIOB,GPIO_Pin_7,0) ;
GPIO_WriteBit(GPIOB,GPIO_Pin_8,0) ;
GPIO_WriteBit(GPIOB,GPIO_Pin_9,0) ;*/
RCC->APB2ENR|=1<<3; //使能PORTB时钟
GPIOB->CRL&=0X00000000;
GPIOB->CRL|=0X33FFFFFF;
GPIOB->CRH&=0X00000000;
GPIOB->CRH|=0XFFFFFF33;
GPIOB->ODR|=0XFFFFFFFF;
}
void comdate(int h,unsigned char data)//0命令 1数据
{
int i;
if(h==0)
PBout(6)=0;
else
PBout(6)=1;
PBout(9)=0;
for(i=0;i<8;i++)
{
if(data&0x80)
PBout(8)=1;
else
PBout(8)=0;
PBout(9)=1;
PBout(9)=0;
data<<=1;
}
}
void chushihua(void)
{
comdate(0,0xae);//close 屏
comdate(0,0x00);//write low address
comdate(0,0x10);//write high address
comdate(0,0xaf);//开屏
/* comdate(0,0x2E);
comdate(0,0x26); // 26/27 light right
comdate(0,0x00);
comdate(0,0x00);
comdate(0,0x07);
comdate(0,0x07);
comdate(0,0x00);
comdate(0,0xFF);
comdate(0,0x2F);*/
}
void LCD_Set_Pos(unsigned char x, unsigned char y)
{
comdate(0,0xb0+y);
comdate(0,((x&0xf0)>>4)|0x10);
comdate(0,(x&0x0f)|0x01);
}
void xianshi(unsigned char x,unsigned char y)
{
int i,j;
int q;
/*for(i=0;i<64;i++)
{
comdate(1,a[i]);
//for(i=0;i<8;i++);
if(i>0&&i%16==0)
{
y=y+1;
x+=8;
}
}*/
for(i=0;i<2;i++)
{
for(j=0;j<32;j++)
{
LCD_Set_Pos(j,i);
comdate(1,a[q++]);
}
}
}
void xianshi1(unsigned char x,unsigned char y)
{
int i,j;
int q;
for(i=0;i<2;i++)
{
for(j=0;j<32;j++)
{
LCD_Set_Pos(j,i+2);
comdate(1,b[q++]);
}
}
}
void xianshi2(unsigned char x,unsigned char y)
{
int i,j;
int q;
for(i=0;i<2;i++)
{
for(j=0;j<32;j++)
{
LCD_Set_Pos(j,i+4);
comdate(1,c[q++]);
}
}
}
void xianshi3(unsigned char x,unsigned char y)
{
int i,j;
int q;
for(i=0;i<8;i++)
{
for(j=0;j<128;j++)
{
LCD_Set_Pos(j,i);
comdate(1,0x00);
}
}
}
int main()
{
int i;
LCD_Init();
chushihua();
xianshi(0,0);//参数毫无意义
xianshi1(0,2);
xianshi2(3,3);
//xianshi3(1,0);
//xianshi(1,0);
//xianshi1(1,0);
/*comdate(0,0x00);
xianshi3(1,0);
//for(i=0;i<100000;i++);
xianshi1(1,0);
comdate(0,0x00);
xianshi3(1,0);
//for(i=0;i<100000;i++);
xianshi2(1,0);
//xianshi2(9,0);*/
while(1);
}
/*for(j=0;j<10;j++)
{
for(i=0;i<8;i++)
comdate(1,a[i]);
// comdate(1,43);
LCD_Set_Pos(x,y+1);
for(i=0;i<8;i++)
comdate(1,a[i+8]);
x+=8;
}*/
上一篇:stm32温湿度-超声波-LCD1602结合项目
下一篇:stm32f103r6仿真计数器程序+Proteus
推荐阅读最新更新时间:2024-11-01 23:30