本帖最后由 fsdSADASDSA 于 2018-11-15 11:15 编辑
这是程序
#include "lcd.h"
#include "sys.h"
unsigned char tab9[]={
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F
};
unsigned char tab0[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
void Delayns(void)
{
__asm("nop");__asm("nop");__asm("nop");__asm("nop");__asm("nop");__asm("nop");
__asm("nop");__asm("nop");__asm("nop");__asm("nop");__asm("nop");__asm("nop");
}
void Delay_t(uint t)
{
uint i,j;
for(i=0;i<t;i++)
for(j=0;j<80;j++);
}
//PB3--CS
//PB4--背光
//PB5--WR
//PB6--DATA
void Initial_LCD()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4 |GPIO_Pin_5|GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
LCD_CS_H();
LCD_WR_H();
LCD_DATA_H();
LCD_RD_L();
delay_ms(10);
LCD_RD_H();
delay_ms(100);
Write_command(0x30);//select 1/4 dut & 1/3 bias
Write_command(0x02);//RC 256K
Write_command(0x52);//system enable
Write_command(0x06);//LCD ON
}
//////////////////////////////////////
void Write_ID(unsigned char ID,unsigned char cnt)
{
unsigned char i;
for(i=0;i<cnt;i++)
{
LCD_WR_L();
delay_us(5);
if(ID&0x80)
LCD_DATA_H();
else
LCD_DATA_L();
LCD_WR_H();
delay_us(5);
ID<<=1;
}
}
void Write_data_bit(unsigned char dat,unsigned char cnt)
{
unsigned char i;
for(i=0;i<cnt;i++)
{
LCD_WR_L();
delay_us(5);
if(dat&0x01)
LCD_DATA_H();
else
LCD_DATA_L();
//delay_us(5);
LCD_WR_H();
delay_us(5);
dat>>=1;
}
}
//写命令函数
void Write_command(unsigned char Command_byte)
{
LCD_CS_L();
delay_us(5);
Write_ID(0x80,4);
Write_ID(Command_byte,8);
LCD_CS_H();
}
//写一个数据
void Singal_data_write(unsigned char address,unsigned char dat)
{
LCD_CS_L();
delay_us(5);
Write_ID(0xa0,3);//write 101
Write_ID(address,6);//address from 0x00
Write_data_bit(dat,4);
LCD_CS_H();delay_us(5);
}
//写所有数据
void Writeall_data_1621(unsigned char *p)
{
unsigned char i;
unsigned char temp_data;
LCD_CS_L();
delay_us(5);
Write_ID(0xa0,3);//write 101
Write_ID(0x00,6);//address from 0x00
for(i=0;i<48;i++)
{
temp_data =p;
Write_data_bit(temp_data,4);
}
LCD_CS_H();
}
#include "sys.h"
#include "lcd.h"
extern unsigned char tab8[];
extern unsigned char tab2[];
extern unsigned char tab9[];
extern unsigned char tab5[];
extern unsigned char tab0[];
extern unsigned char tab4[];
int main(void)
{
delay_init(48);
Initial_LCD();
delay_ms(1000);
delay_ms(1000);
Writeall_data_1621(tab0); //清屏
delay_ms(100);
while(1)
{
Writeall_data_1621(tab9); Delay_t(3000);//全部显示
}
}
|