//以下采用的是模块化编程
//液晶写数据写命令
//读数据读命令
#include"yejing12864.h"
#include"delay.h"
#include<macros.h>
#include<iom16v.h>
#define uint unsigned int
#define uchar unsigned char
#include"delay.h"
#include<macros.h>
#include<iom16v.h>
#define uint unsigned int
#define uchar unsigned char
//定义使能
#define LCD_EN1 PORTC|=BIT(4)
#define LCD_EN0 PORTC&=~BIT(4)
#define LCD_EN1 PORTC|=BIT(4)
#define LCD_EN0 PORTC&=~BIT(4)
//命令模式
#define LCD_RS1 PORTC|=BIT(5)
#define LCD_RS0 PORTC&=~BIT(5)
#define LCD_RS0 PORTC&=~BIT(5)
//读写控制
#define LCD_WR1 PORTC|=BIT(6)
#define LCD_WR0 PORTC&=~BIT(6)
#define LCD_WR1 PORTC|=BIT(6)
#define LCD_WR0 PORTC&=~BIT(6)
//串并口控制
#define LCD_PSB1 PORTC|=BIT(7)
#define LCD_PSB0 PORTC&=~BIT(7)
#define LCD_PSB1 PORTC|=BIT(7)
#define LCD_PSB0 PORTC&=~BIT(7)
//写地址
void write12864_com(uint com)
{
DDRB=0xff;
PORTB=0xff;
LCD_RS0;
void write12864_com(uint com)
{
DDRB=0xff;
PORTB=0xff;
LCD_RS0;
LCD_WR0;
LCD_EN0;
PORTB=com;
delay_xms(1);
LCD_EN1;
delay_xms(1);
LCD_EN0;
}
LCD_EN0;
PORTB=com;
delay_xms(1);
LCD_EN1;
delay_xms(1);
LCD_EN0;
}
//写数据
void write12864_date(uint date)
{
DDRB=0xff;
PORTB=0xff;
LCD_RS1;
LCD_WR0;
void write12864_date(uint date)
{
DDRB=0xff;
PORTB=0xff;
LCD_RS1;
LCD_WR0;
LCD_EN0;
PORTB=date;
delay_xms(1);
LCD_EN1;
delay_xms(1);
LCD_EN0;
}
PORTB=date;
delay_xms(1);
LCD_EN1;
delay_xms(1);
LCD_EN0;
}
//读数据
uchar read_12864(void)
{
uchar shuju;
DDRB=0x00;
PORTB=0xff;
LCD_RS1;
uchar read_12864(void)
{
uchar shuju;
DDRB=0x00;
PORTB=0xff;
LCD_RS1;
LCD_WR1;
LCD_EN0;
delay_xms(1);
LCD_EN1;
delay_xms(1);
shuju=PINB;
delay_xms(1);
LCD_EN0;
return(shuju);
}
//12864液晶初始化
void LCD12864_init(字符串长度的正确表示void)
{
LCD_PSB1;
write12864_com(0x30);
LCD_EN0;
delay_xms(1);
LCD_EN1;
delay_xms(1);
shuju=PINB;
delay_xms(1);
LCD_EN0;
return(shuju);
}
//12864液晶初始化
void LCD12864_init(字符串长度的正确表示void)
{
LCD_PSB1;
write12864_com(0x30);
delay_xms(1);
write12864_com(0x0c);
delay_xms(1);
write12864_com(0x01);
delay_xms(1);
}
write12864_com(0x0c);
delay_xms(1);
write12864_com(0x01);
delay_xms(1);
}
//12864液晶画图时的清屏函数
void clrRAM_12864(void)
{
uchar i,j;
for(i=0;i<64;i++)
for(j=0;j<16;j++)
{
write12864_com(0x34);
write12864_com(i+0x80);
void clrRAM_12864(void)
{
uchar i,j;
for(i=0;i<64;i++)
for(j=0;j<16;j++)
{
write12864_com(0x34);
write12864_com(i+0x80);
write12864_com(j+0x80);
write12864_com(0x30);
write12864_date(0x00);
write12864_date(0x00);
}
}
write12864_com(0x30);
write12864_date(0x00);
write12864_date(0x00);
}
}
//延时函数 atmage16单片机4M晶振1us和1ms的准确延时
#include"delay.h"
void delay_xus(uint n)
{
uint i;
n=n*5/16;
for(i=0;i<n;i++);
}
void delay_xus(uint n)
{
uint i;
n=n*5/16;
for(i=0;i<n;i++);
}
void delay_xms(uint x)
{
while(x--)
{
uint i;
for(i=0;i<666;i++);
}
}
{
while(x--)
{
uint i;
for(i=0;i<666;i++);
}
}
//主函数,在12864液晶上显示有0通道出来的数据,转换成点
#include<iom16v.h>
#include<macros.h>
#include<math.h>
#include"delay.h"
#include<macros.h>
#include<math.h>
#include"delay.h"
#include"yejing12864.h"
#include"dianxs12864.h"
#include"xianxs12864.h"
#include"zbx.h"
#define uchar unsigned char
#define uint unsigned int
uchar table[]="0123456789";
uint adc_result;
void ad_init(void)
{
ADMUX=0x40;//参考电压的设置,数据对齐方式,通道的选择
ADCSRA=0xe6;//
delay_xms(1000);
}
void main(void)
#include"dianxs12864.h"
#include"xianxs12864.h"
#include"zbx.h"
#define uchar unsigned char
#define uint unsigned int
uchar table[]="0123456789";
uint adc_result;
void ad_init(void)
{
ADMUX=0x40;//参考电压的设置,数据对齐方式,通道的选择
ADCSRA=0xe6;//
delay_xms(1000);
}
void main(void)
{
uint q,b,s,g;
DDRB=0xff;//端口初始化
PORTB=0xff;
DDRA&=~BIT(0);//电位器接在PA0上
PORTA&=~BIT(0);
DDRC=0xf0;
PORTC=0xf0;
clrRAM_12864();
delay_xms(50);
LCD12864_init();
ad_init();
while(1)
{
uint i,xa,ya,py;
uint q,b,s,g;
DDRB=0xff;//端口初始化
PORTB=0xff;
DDRA&=~BIT(0);//电位器接在PA0上
PORTA&=~BIT(0);
DDRC=0xf0;
PORTC=0xf0;
clrRAM_12864();
delay_xms(50);
LCD12864_init();
ad_init();
while(1)
{
uint i,xa,ya,py;
uint pro_result;
uint adc_l,adc_h;
adc_l=ADCL;
adc_h=ADCH;
adc_result=adc_h*256+adc_l;
zbx();
if(pro_result!=adc_result);
{
pro_result=adc_result;
ya=fabs(32-adc_result*32/1023);
if(xa==0)
{
py=ya;
dianxs12864(8,ya,1);
}
uint adc_l,adc_h;
adc_l=ADCL;
adc_h=ADCH;
adc_result=adc_h*256+adc_l;
zbx();
if(pro_result!=adc_result);
{
pro_result=adc_result;
ya=fabs(32-adc_result*32/1023);
if(xa==0)
{
py=ya;
dianxs12864(8,ya,1);
}
xianxs_ry(xa+7,py,xa+8,ya,1);
py=ya;
xa=xa+2;
if(xa>=128)
{
xa=0;
clrRAM_12864();
delay_xms(50);
}
}
q=adc_result/1000;
b=adc_result%1000/100;
s=adc_result%100/10;
g=adc_result%10;
write12864_com(0x9c);
py=ya;
xa=xa+2;
if(xa>=128)
{
xa=0;
clrRAM_12864();
delay_xms(50);
}
}
q=adc_result/1000;
b=adc_result%1000/100;
s=adc_result%100/10;
g=adc_result%10;
write12864_com(0x9c);
write12864_date(table[q]);
write12864_date(table[b]);
write12864_date(table[s]);
write12864_date(table[g]);
}
}
/*#pragma interrupt_handler AD_isr:15;
void AD_isr(void)
{
uint adc_l,adc_h;
adc_l=ADCL;
adc_h=ADCH;
adc_result=adc_h*256+adc_l;
}*/
write12864_date(table[b]);
write12864_date(table[s]);
write12864_date(table[g]);
}
}
/*#pragma interrupt_handler AD_isr:15;
void AD_isr(void)
{
uint adc_l,adc_h;
adc_l=ADCL;
adc_h=ADCH;
adc_result=adc_h*256+adc_l;
}*/
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论