程序時網(wǎng)上看到的,我剛好也用到這里邊的一些子函數(shù),覺得還不錯,拿出來給大家參考,希望對和我一樣的朋友有所幫助#include
#include
本文引用地址:http://m.butianyuan.cn/article/201611/320232.htm#define BusyCheck (PIND&0x40) //Busy,PD6,忙標(biāo)志
#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,復(fù)位
#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); //設(shè)置X地址為
SdCmd(0x70);SdCmd(Y); //設(shè)置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); //設(shè)置X地址為0
SdCmd(0x70);SdCmd(0x00); //設(shè)置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); //設(shè)置X地址為0
SdCmd(0x70);SdCmd(0x00); //設(shè)置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); //設(shè)置X地址
SdCmd(0x70);SdCmd(Y_Point); //設(shè)置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); //設(shè)置X地址
SdCmd(0x70);SdCmd(Y); //設(shè)置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); //設(shè)置X地址
SdCmd(0x70);SdCmd(Y); //設(shè)置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); //光標(biāo)控制寄存器
SdCmd(0x18);SdCmd(0x20); //光標(biāo)大小控制寄存器
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方向光標(biāo)寄存器
SdCmd(0x70);SdCmd(0x00); //Y方向光標(biāo)寄存器
SdCmd(0x80);SdCmd(0x2a); //閃爍時間寄存器
SdCmd(0x90);SdCmd(0x3e); //移位時鐘控制寄存器
SdCmd(0xe0);SdCmd(0x00); //數(shù)據(jù)模式寄存器
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) //補(bǔ)豎線
{
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++) //將前一列的數(shù)據(jù)清空
{
Clear(X_Pixel,Stick);
}
}
}
}
評論