|
程序是自己按照12864思路写的,但是屏幕上就是没什么显示,连乱码都没有,芯片用的是stm32f103ve,不知道是不是哪个地方配置有误,希望大声能指点一下!程序贴上!
#include "stm32f10x.h"
#define data 1
#define comm 0
#define f_page 0xb8
#define f_row 0xc0
#define f_line 0x00
typedef unsigned char U8;
typedef unsigned int U16;
void chk_busy (U8 choe1,U8 choe2);
#define GPIO_Pin_ALL1 GPIO_DATA_0_PIN|GPIO_DATA_1_PIN|GPIO_DATA_2_PIN|GPIO_DATA_3_PIN|GPIO_DATA_4_PIN\
|GPIO_DATA_5_PIN|GPIO_DATA_6_PIN|GPIO_DATA_7_PIN
#define GPIO_RES GPIOE // RES端口组
#define GPIO_RES_PIN GPIO_Pin_15 // RES端口号
#define RCC_GPIO_RES RCC_APB2Periph_GPIOE // RES时钟组
#define GPIO_A0 GPIOB // A0端口组
#define GPIO_A0_PIN GPIO_Pin_15 // A0口号
#define RCC_GPIO_A0 RCC_APB2Periph_GPIOB // A0时钟组
#define GPIO_RW GPIOB // RW端口组
#define GPIO_RW_PIN GPIO_Pin_14 // RW口号
#define RCC_GPIO_RW RCC_APB2Periph_GPIOB // RW时钟组
#define GPIO_E2 GPIOB // E2端口组
#define GPIO_E2_PIN GPIO_Pin_13 // E2口号
#define RCC_GPIO_E2 RCC_APB2Periph_GPIOB // E2时钟组
#define GPIO_E1 GPIOB // A0端口组
#define GPIO_E1_PIN GPIO_Pin_12 // A0口号
#define RCC_GPIO_E1 RCC_APB2Periph_GPIOB // A0时钟组
#define GPIO_DATA_0 GPIOD // 数据线0_端口组
#define GPIO_DATA_0_PIN GPIO_Pin_8 // 数据线0_端口号
#define GPIO_DATA_1 GPIOD // 数据线1_端口组
#define GPIO_DATA_1_PIN GPIO_Pin_9 // 数据线1_端口号
#define GPIO_DATA_2 GPIOD // 数据线2_端口组
#define GPIO_DATA_2_PIN GPIO_Pin_10 // 数据线2_端口号
#define GPIO_DATA_3 GPIOD // 数据线3_端口组
#define GPIO_DATA_3_PIN GPIO_Pin_11 // 数据线3_端口号
#define GPIO_DATA_4 GPIOD // 数据线4_端口组
#define GPIO_DATA_4_PIN GPIO_Pin_12 // 数据线4_端口号
#define GPIO_DATA_5 GPIOD // 数据线5_端口组
#define GPIO_DATA_5_PIN GPIO_Pin_13 // 数据线5_端口号
#define GPIO_DATA_6 GPIOD // 数据线6_端口组
#define GPIO_DATA_6_PIN GPIO_Pin_14 // 数据线6_端口号
#define GPIO_DATA_7 GPIOD // 数据线7_端口组
#define GPIO_DATA_7_PIN GPIO_Pin_15 // 数据线7_端口号
#define RCC_GPIO_DATA RCC_APB2Periph_GPIOD // 数据线时钟组
#define SET_RES GPIO_SetBits(GPIO_RES, GPIO_RES_PIN)
#define CLE_RES GPIO_ResetBits(GPIO_RES, GPIO_RES_PIN) // 输出0
#define SET_RW GPIO_SetBits(GPIO_RW, GPIO_RW_PIN) //RW 读写 输出1
#define CLE_RW GPIO_ResetBits(GPIO_RW, GPIO_RW_PIN) // 输出0
#define SET_K GPIO_SetBits(GPIO_K, GPIO_K_PIN) //输出为1,亮度调整pwm
#define CLE_K GPIO_ResetBits(GPIO_K, GPIO_K_PIN) // 输出0
#define SET_A0 GPIO_SetBits(GPIO_A0, GPIO_A0_PIN)
#define CLE_A0 GPIO_ResetBits(GPIO_A0, GPIO_A0_PIN) // 输出0
#define SET_E2 GPIO_SetBits(GPIO_E2, GPIO_E2_PIN) //RW 读写 输出1
#define CLE_E2 GPIO_ResetBits(GPIO_E2, GPIO_E2_PIN) // 输出0
#define SET_E1 GPIO_SetBits(GPIO_E1, GPIO_E1_PIN) //输出为1
#define CLE_E1 GPIO_ResetBits(GPIO_E1, GPIO_E1_PIN) // 输出0
unsigned char num[]={
/*"0"*/ 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
/*"1"*/ 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
/*"2"*/ 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,
/*"3"*/ 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,
/*"4"*/ 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
/*"5"*/ 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,
/*"6"*/ 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,
/*"7"*/ 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,
/*"8"*/ 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
/*"9"*/ 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00
};
unsigned char company[]={
/*汉字*/0x00,0x00,0xFC,0x04,0x04,0x04,0x04,0x05,0x06,0x04,0x04,0x04,0x04,0x04,0x04,0x00,
0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xE0,0x00,0x00,0xFF,0x20,0xC0,0x00,0xFE,0x10,0x60,0x80,0x00,0xFF,0x00,0x00,
0x01,0x80,0x60,0x18,0x07,0x00,0x00,0x00,0x7F,0x00,0x00,0x01,0x00,0xFF,0x00,0x00,
0x04,0x04,0x04,0xE4,0x24,0x24,0x25,0xFE,0x24,0x24,0x24,0x24,0xE4,0x04,0x04,0x00,
0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0xFF,0x00,0x00,0x10,0x20,0x1F,0x00,0x00,0x00,
0x40,0x41,0xCE,0x04,0x00,0xF0,0x90,0x90,0x90,0xFF,0x90,0x90,0x90,0xF0,0x00,0x00,
0x40,0x20,0x1F,0x20,0x40,0x5F,0x48,0x48,0x48,0x4F,0x48,0x48,0x48,0x5F,0x40,0x00,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,
0x40,0x44,0x54,0x64,0x45,0x7E,0x44,0x44,0x44,0x7E,0x45,0x64,0x54,0x44,0x40,0x00,
0x00,0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,0x00
};
unsigned char FM[]={
/*F*/ 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,
/*M*/ 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00
};
unsigned char AM[]={
/*A*/ 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,
/*M*/ 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00
};
unsigned char diantai[]={
/*电*/ 0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00,
0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00,
/*台*/ 0x00,0x00,0x40,0x60,0x50,0x48,0x44,0x63,0x22,0x20,0x20,0x28,0x70,0x20,0x00,0x00,
0x00,0x00,0x00,0x7F,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x7F,0x00,0x00,0x00,0x00
};
unsigned char xiaoshudian[]={
/*小数点*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00
};
unsigned char K[]={
/*K*/ 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00
};
void delay_ms(unsigned int time) //延时10ms
{
unsigned int i=0;
while(time--)
{
i=12000;
while(i--);
}
}
void delay_us(unsigned int time) //延时1us
{
unsigned int i=0;
while(time--)
{
i=1;
while(i--);
}
}
void GPIO_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //声明结构体
/********Data及按键端口设置*************/
RCC_APB2PeriphClockCmd(RCC_GPIO_DATA, ENABLE); //打开端口D时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_ALL1; // D0~D15(除了4,5,6,7)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //标准输出模式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50M时钟速度
GPIO_Init(GPIO_DATA_0, &GPIO_InitStructure); //初始化端口
/********读/写端口设置**********/
RCC_APB2PeriphClockCmd(RCC_GPIO_RW, ENABLE); //打开端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_RW_PIN|GPIO_A0_PIN|GPIO_E2_PIN|GPIO_E1_PIN; // 端口A0,R/W,E2,E1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //标准输出模式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50M时钟速度
GPIO_Init(GPIO_RW, &GPIO_InitStructure);
/********指令/数据端口设置**********/
RCC_APB2PeriphClockCmd(RCC_GPIO_RES, ENABLE); //打开端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_RES_PIN; // 使能端口
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50M时钟速度
GPIO_Init(GPIO_RES, &GPIO_InitStructure);
}
void wr_lcd (U8 choe1,U8 choe2,U8 data_comm,U8 content)
{
U16 temp = 0;
chk_busy (choe1,choe2);
if(data_comm) //写数据
{
SET_A0; //a0至位,写数据
CLE_RW;//rw清零,写模式
}
else //写命令
{
CLE_A0; //a0清零,写指令
CLE_RW; //rw清零,写模式
}
if(choe1==1)
{
SET_E1; //e1置位,左半屏使能
temp =GPIOD->ODR ; //读取端口状态,读——修改——写的方式,这里不用库
temp &= 0xff00;
temp |= content;
GPIO_Write(GPIOD,temp);
delay_us(2);
CLE_E1;
delay_us(2);
SET_E1;
SET_RW;
}
if(choe2==1)
{
SET_E2;
temp = GPIOD->ODR;
temp &= 0xff00;
temp |= content;
GPIO_Write(GPIOD,temp);
delay_us(2);
CLE_E2;
delay_us(2);
SET_E1;
SET_RW;
}
}
void chk_busy (U8 choe1,U8 choe2)
{
U16 temp = 0;
if(choe1==1) //选择左边显示
{
CLE_A0;
delay_us(2);
SET_RW;
delay_us(2);
SET_E1;
delay_us(2);
temp = GPIO_ReadInputData(GPIOD);
while(temp & 0x0080)
{
temp = GPIO_ReadInputData(GPIOD);
}
CLE_E1;
delay_us(2);
}
if(choe2==1) //选择右边显示
{
CLE_A0;
delay_us(2);
SET_RW;
delay_us(2);
SET_E2;
delay_us(2);
temp = GPIO_ReadInputData(GPIOD);
while(temp & 0x0080)
{
temp = GPIO_ReadInputData(GPIOD);
}
SET_E2;
delay_us(2);
}
}
void init_lcd (void)
{
CLE_E2;
CLE_E1;
CLE_RES;
delay_ms(1);
SET_RES;
delay_ms(1);
wr_lcd (1,1,comm,0xc0);
delay_us(1);
wr_lcd (1,1,comm,0xaf); //显示打开
delay_us(1);
wr_lcd (1,1,comm,0xa4); //动态驱动
delay_us(1);
wr_lcd (1,1,comm,0xa9); //刷新时钟设置1/32
delay_us(1);
wr_lcd (1,1,comm,0xa0); //clockwise
delay_us(1);
wr_lcd (1,1,comm,0xe0); //启动改写模式
//delay_us(1);
}
void clear_screen(void)
{
unsigned char i,j;
for(i=0;i<4;i++)
{
wr_lcd (1,1,comm,f_page+i); //选择页的起始地址
wr_lcd (1,1,comm,f_row); //选择起始行0xc0
wr_lcd (1,1,comm,f_line); //选择起始列0x00
for(j=0;j<61;j++)
{
wr_lcd (1,1,data,0);
}
}
}
void write_one_char(unsigned char x,unsigned char y,unsigned char *cha)
{
unsigned char i,ii;
for(ii=0;ii<2;ii++) //上下半屏分写
{
if(y>=2) //左右半屏分写
{
wr_lcd (0,1,comm,f_page+x+ii); //值页
wr_lcd (0,1,comm,f_row+8*x); //扫描行
wr_lcd (0,1,comm,f_line+13+8*(y-2));//值列
for(i=0;i<8;i++)
{
wr_lcd (0,1,data,cha[8*ii+i]);
}
wr_lcd (0,1,comm,f_row); //执行滚屏
}
else
{
wr_lcd (1,0,comm,f_page+x+ii);
wr_lcd (1,0,comm,f_row+8*x);
wr_lcd (1,0,comm,f_line+8*y+13);
for(i=0;i<8;i++)
{
wr_lcd (1,0,data,cha[8*ii+i]);
}
wr_lcd (1,0,comm,f_row);
}
}
}
///////////////////////////////////////////////////////////////////
/*
写任意像素16*16到指定位置
*/
void write_one_chinese(unsigned char x,unsigned char y,unsigned char *cha)
{
U8 i,ii;
for(ii=0;ii<2;ii++) //上下半屏分写
{
if(y>=3) //左右半屏分写
{
wr_lcd (0,1,comm,f_page+x+ii); //值页
wr_lcd (0,1,comm,f_row+8*x); //扫描
wr_lcd (0,1,comm,f_line+16*(y-3));//值列 ?
for(i=0;i<16;i++)
{
wr_lcd (0,1,data,cha[16*ii+i]);
}
wr_lcd (0,1,comm,f_row); //执行滚屏
}
else
{
wr_lcd (1,0,comm,f_page+x+ii);
wr_lcd (1,0,comm,f_row+8*x);
wr_lcd (1,0,comm,f_line+16*y+13);
for(i=0;i<16;i++)
{
wr_lcd (1,0,data,cha[16*ii+i]);
}
wr_lcd (1,0,comm,f_row);
}
}
}
//////////////////////////////////////////////////////////////////
/************任意位置写字符串:A,B,C,D,E,F,M************************************/
void write_chars(unsigned char x,unsigned char y,unsigned char *cha,unsigned char quantity)
{
unsigned char i;
for(i=0;i<quantity;i++)
{
write_one_char(x,y+i,cha+16*i);
}
}
/***********任意位置写汉字串************************************/
void write_characters(unsigned char x,unsigned char y,unsigned char *cha,unsigned char quantity)
{
unsigned char i;
for(i=0;i<quantity;i++)
{
write_one_chinese(x,y+i,cha+32*i);
}
}
/*将得到的10进制数显示*/
void convert_display(U8 point)
{
U8 j1,j2,j3,j4;
if(point>=2000)
{
j1 = point/10000; //数据的最高位
if(0 == j1)
{
j2 = point/1000 ; //数据的第二位
j3 = (point-j2*1000)/100; //数据的第三位
j4 = point%100/10; //数据的最低位
}
else
{
j2 = 0; //数据的第二位
j3 = (point-10000)/100; //数据的第三位
j4 = point%100/10; //数据的最低位
}
}
else
{
j1 = point/1000;
if(0 == j1)
{
j2 = point/100;
j3 = (point-j2*100)/10;
j4 = (point-j2*100)%10;
}
else
{
j2 = (point-1000*j1)/100;
j3 = (point-j1*1000-j2*100)/10;
j4 = (point-j1*1000-j2*100)%10;
}
}
if(point>=2000) //显示FM频率
{
if(0 == j1)
{
write_one_char(2,3,num+16*j2);
write_one_char(2,4,num+16*j3);
write_one_char(2,5,xiaoshudian); //小数点位
write_one_char(2,6,num+16*j4); //单位M
write_one_char(2,7,FM+16);
}
else
{
write_one_char(2,2,num+16*j1);
write_one_char(2,3,num+16*j2);
write_one_char(2,4,num+16*j3);
write_one_char(2,5,xiaoshudian); //小数点位
write_one_char(2,6,num+16*j4);
write_one_char(2,7,FM+16);
}
}
else //显示AM频率
{
if(0 == j1)
{
write_one_char(2,3,num+16*j2);
write_one_char(2,4,num+16*j3);
write_one_char(2,5,num+16*j4);
write_one_char(2,6,K); //单位K
}
else
{
write_one_char(2,2,num+16*j1);
write_one_char(2,3,num+16*j2);
write_one_char(2,4,num+16*j3);
write_one_char(2,5,num+16*j4);
write_one_char(2,6,K);
}
}
}
int main(void)
{
SystemInit();
GPIO_init();
init_lcd ();
clear_screen();
while(1)
{
write_characters(0,0,company,6);
}
}
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|