您的位置 首页 传感器

使用单片机以及24064液晶制造简略的示波器

程序时网上看到的,我刚好也用到这里边的一些子函数,觉得还不错,拿出来给大家参考,希望对和我一样的朋友有所帮助includeiom16vh>i

程序时网上看到的,我刚好也用到这里边的一些子函数,觉得还不错,拿出来给我们参阅,期望对和我相同的朋友有所协助

#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);
}

// Conversion time: 104uS
void adc_init(void)
{
ADCSR = 0x00; //disable adc
ADMUX = 0x20; //select adc input 0
ACSR = 0x80;
ADCSR = 0xEE;
}

#pragma interrupt_handler adc_isr:15
void adc_isr(void)
{
Voltage = ADCH>>2;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
PORT_Init();
adc_init();

MCUCR = 0x00;
GICR = 0x00;
//TIMSK = 0x01; //timer interrupt sources
SEI(); //re-enable interrupts
InitLCDModule();
}
flash char shi[]=”示”;
flash char bo[]=”波”;
flash char qi[]=”器”;
void main(void)
{
char X_Pixel = 0;
char Stick = 0;
char X_Disappear = 0;
char Y0 = 0;
char Y1 = 0;
init_devices();
CLS();
DisplayTextScreen(28,0,shi);
DisplayTextScreen(28,23,bo);
DisplayTextScreen(28,47,qi);
for (Stick=0;Stick<=64;Stick++)
{
Point(224,Stick,1);
}
while(1)
{
for(X_Pixel=0;X_Pixel<221;X_Pixel++)
{
Y1 = 64-Voltage;
Point(X_Pixel,Y1,1); //制作电压点

if (Y1>Y0) //补竖线
{
if ( (Y1-Y0)>1 )
{
for (Stick=Y0;Stick<=Y1;Stick++)
{
Point(X_Pixel,Stick,1);
}
}
}
else if (Y1 {
if ( (Y0-Y1)>1 )
{
for (Stick=Y1;Stick<=Y0;Stick++)
{
Point(X_Pixel,Stick,1);
}
}
}
Y0 = Y1;
for (Stick=0;Stick<64;Stick++) //将前一列的数据清空
{
Clear(X_Pixel,Stick);
}
}
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/yingyong/chuanganqi/261060.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部