微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 利用单片机以及24064液晶制作简单的示波器

利用单片机以及24064液晶制作简单的示波器

时间:11-23 来源:互联网 点击:
程序时网上看到的,我刚好也用到这里边的一些子函数,觉得还不错,拿出来给大家参考,希望对和我一样的朋友有所帮助

#include
#include

#define BusyCheck (PIND&0x40) //Busy,PD6,忙标志
#define CS PORTD &= (~0x20) //_CS,PD5,片选
#define CNS PORTD |= 0x20
#define DisplayRegister PORTD |= 0x10 //RS,PD4,寄存器选择
#define CommandRegister PORTD &= (~0x10)
#define WriteEnable PORTD &= (~0x08) //_RW,PD3,写使能
#define WriteDisable PORTD |= 0x08
#define ReadEnable PORTD &= (~0x04) //_RD,PD2,读使能
#define ReadDisable PORTD |= 0x04
#define RST PORTD &= (~0x02) //_RST,PD1,复位
#define NotRST PORTD |= 0x02
#define LCDBUS PORTC

char ReadData = 0;
char Voltage = 0;

void PORT_Init(void)
{
PORTA = 0xff;
DDRA = 0x00;
PORTB = 0xFF;
DDRB = 0xFF;
PORTC = 0xFF;
DDRC = 0xFF;
PORTD = 0xFF;
DDRD = 0xBF;
}

void Delay(char DelayTimes)
{
char i,k;
for (i=0;i {
for (k=0;k<250;k++)
{
asm("nop");
}
}
}
void Delay2(int DelayTimes)
{
int i,k;
for (i=0;i {
for (k=0;k<2000;k++)
{
asm("nop");
}
}
}

void SdCmd(char Command)
{
ReadDisable;
CommandRegister;
LCDBUS = Command;

asm("nop");asm("nop");asm("nop");asm("nop");
WriteEnable;
asm("nop");asm("nop");asm("nop");asm("nop");
WriteDisable;
asm("nop");
}

void SdData (char DisplayData)
{
ReadDisable;
DisplayRegister;
LCDBUS = DisplayData;

WriteEnable;
asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");
WriteDisable;
asm("nop");
}

void DisplayTextScreen(char X,char Y,flash char *TextData)
{
char TempData = 0;
char i = 0;
char j = 0;
SdCmd(0x60);SdCmd(X); //设置X地址为
SdCmd(0x70);SdCmd(Y); //设置Y地址为
SdCmd(0x00);SdCmd(0xcd); //正常供电模式,文本显示,显示开,正常显示
for (j=0;j<2;j++)
{
SdData(*(TextData+j));
}
}

void DisplayGraphyScreen(flash char *GraphyData)
{
char TempData = 0;
char i = 0;
char j = 0;
SdCmd(0x60);SdCmd(0x00); //设置X地址为0
SdCmd(0x70);SdCmd(0x00); //设置Y地址为0
SdCmd(0x00);SdCmd(0xc5); //正常供电模式,图形模式,显示开,正常显示
for (j=0;j<64;j++)
{
for (i=0;i<30;i++)
{
TempData = (*(GraphyData+(j*30)+i));
SdData(TempData);
}
}
}

void CLS(void)
{
int j = 0;
SdCmd(0x60);SdCmd(0x00); //设置X地址为0
SdCmd(0x70);SdCmd(0x00); //设置Y地址为0
SdCmd(0x00);SdCmd(0xc5); //正常供电模式,图形模式,显示开,正常显示
for (j=0;j<1920;j++)
{
SdData(0);
}
}

void RdData(char X,char Y_Point)
{
SdCmd(0x60);SdCmd(X); //设置X地址
SdCmd(0x70);SdCmd(Y_Point); //设置Y地址
DDRC = 0x00;
WriteDisable;
DisplayRegister;
ReadDisable;
ReadEnable;
asm("nop");asm("nop");asm("nop");asm("nop");
ReadData = PINC&0xff;
DDRC = 0xff;

}

void Point (char X,char Y,char State)
{
char X_Temp = 0;
char X_Position = 0;
X_Temp = X;
while (X_Temp>7)
{
X_Position++;
X_Temp = X_Temp-8;
}
if (X_Temp<=7)
{
RdData(X_Position,Y);
SdCmd(0x60);SdCmd(X_Position); //设置X地址
SdCmd(0x70);SdCmd(Y); //设置Y地址
SdCmd(0x00);SdCmd(0xc5); //正常供电模式,图形模式,显示开,正常显示
if (State == 1)
{
SdData((0x80>>X_Temp)|ReadData);
}
else
{
SdData((~(0x80>>X_Temp))&ReadData);
}
}
}

void Clear (char X,char Y)
{
char X_Temp = 0;
char X_Position = 0;
X_Temp = X;
while (X_Temp>7)
{
X_Position++;
X_Temp = X_Temp-8;
}
if (X_Temp<=7)
{
X_Position = X_Position+1;
if (X_Position>27)
{
X_Position = 0;
}
SdCmd(0x60);SdCmd(X_Position); //设置X地址
SdCmd(0x70);SdCmd(Y); //设置Y地址
SdData(0);
}
}

void InitLCDModule(void)
{
CS;
NotRST;
Delay(250);
RST;
Delay(250);
Delay(250);
NotRST;
Delay(250);
SdCmd(0x00);SdCmd(0xc5); //LCD控制寄存器
SdCmd(0x08);SdCmd(0x73); //通用寄存器
SdCmd(0x10);SdCmd(0xe9); //光标控制寄存器
SdCmd(0x18);SdCmd(0x20); //光标大小控制寄存器
SdCmd(0x20);SdCmd(0x1d); //活动窗右边界寄存器
SdCmd(0x28);SdCmd(0x1d); //显示窗右边界寄存器
SdCmd(0x30);SdCmd(0x3f); //活动窗底部边界寄存器
SdCmd(0x38);SdCmd(0x3f); //显示窗底部边界寄存器
SdCmd(0x40);SdCmd(0x00); //活动窗左边界寄存器
SdCmd(0x50);SdCmd(0x00); //活动窗顶边界寄存器
SdCmd(0x48);SdCmd(0x00); //显示窗左边界寄存器
SdCmd(0x58);SdCmd(0x00); //显示窗顶部寄存器
SdCmd(0x60);SdCmd(0x00); //X方向光标寄存器
SdCmd(0x70);SdCmd(0x00); //Y方向光标寄存器
SdCmd(0x80);SdCmd(0x2a); //闪烁时间寄存器
SdCmd(0x90);SdCmd(0x3e); //移位时钟控制寄存器
SdCmd(0xe0);SdCmd(0x00); //数据模式寄存器
SdCmd(0xf0);SdCmd(0xa0); //字体控制寄存器
Delay(20);
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top