📄 12121.c
字号:
/*======================================================================================
======================================================================================*/
#include <avr/io.h>
#include<avr/interrupt.h>
#define uchar unsigned char
#define uint unsigned int
/***************************************************************************/
#define LCDM_RS_DDR DDRA
#define LCDM_RS_PORT PORTA
#define LCDM_RW_DDR DDRA
#define LCDM_RW_PORT PORTA
#define LCDM_EN_DDR DDRA
#define LCDM_EN_PORT PORTA
#define LCDM_LEDA_DDR DDRA
#define LCDM_LEDA_PORT PORTA
/***************************************************************************/
#define LCDM_RS_PINNum (1<<0)
#define LCDM_RW_PINNum (1<<1)
#define LCDM_EN_PINNum (1<<2)
#define LCDM_LEDA_PINNum (1<<3)
/***************************************************************************/
#define SRS() LCDM_RS_PORT|=LCDM_RS_PINNum
#define CRS() LCDM_RS_PORT&=~LCDM_RS_PINNum
#define SRW() LCDM_RW_PORT|=LCDM_RW_PINNum
#define CRW() LCDM_RW_PORT&=~LCDM_RW_PINNum
#define SEN() LCDM_EN_PORT|=LCDM_EN_PINNum
#define CEN() LCDM_EN_PORT&=~LCDM_EN_PINNum
#define SLED() LCDM_LEDA_PORT&=~LCDM_LEDA_PINNum
#define CLED() LCDM_LEDA_PORT|=LCDM_LEDA_PINNum
/***************************************************************************/
#define LCDM_DATA_DDR DDRB
#define LCDM_DATA_PORT PORTB
#define LCDM_DATA_PIN PINB
/***************************************************************************/
#define lcd_funtion_base 0x30 //基本指令集
#define lcd_display_state 0x08 //开显示
#define lcd_clear_display 0x01 //清显示
#define lcd_address_to_zero2 0x04 //位地址归位
#define lcd_funtion_additional 0x34 //扩展指令集
#define lcd_move_select 0x80 //
#define lcd_gdram_address 0x80 //设置GDRAM地址
#define lcd_set_ddram_address 0x80 //设置DDRAM地址
/***************************************************************************/
uchar COUNT3,COUNT2,COUNT1,LCD_X,LCD_Y,pin;
/***********************************************************/
uint temp=0;
uint capturetime=0;
uchar time=0;
uchar down=0;
uchar sigtem=0;
/***********************************************************/
void conport_init()
{
LCDM_RS_DDR |=LCDM_RS_PINNum;
LCDM_RW_DDR |=LCDM_RW_PINNum;
LCDM_EN_DDR |=LCDM_EN_PINNum;
LCDM_LEDA_DDR |=LCDM_LEDA_PINNum;
}
/***********************************************************/
//
/***********************************************************/
void delay_nms(uint time)
{
uint b;
for(;time>0;time--)
{
for(b=0;b<379;b++)
{
asm("nop");
}
}
}
/***********************************************************/
/***********************************************************/
uchar lcd_read_state(void)
{
uchar temp;
LCDM_DATA_DDR =0X00;
LCDM_DATA_PORT=0xff;
CRS();
SRW();
SEN();
asm("nop");
asm("nop");
temp=LCDM_DATA_PIN;
asm("nop");
CEN();
asm("nop");
return (temp);
}
/***********************************************************/
/***********************************************************/
uchar lcd_data_read(void)
{
uchar temp;
LCDM_DATA_DDR =0x00;
LCDM_DATA_PORT=0xff;
SRS();
SRW();
SEN();
asm("nop");
asm("nop");
temp=LCDM_DATA_PIN;
asm("nop");
CEN();
asm("nop");
return (temp);
}
/***********************************************************/
/***********************************************************/
uchar lcd_check_busy(void)
{
uchar temp;
temp=lcd_read_state();
temp&=0x80;
if(temp==0x80)
{
return (1);
}
else
{
return (0);
}
}
/***********************************************************/
/***********************************************************/
void lcd_data_write(uchar temp)
{
while(lcd_check_busy())
{
asm("nop");
}
LCDM_DATA_DDR =0xff;
LCDM_DATA_PORT=0x0;
SRS();
CRW();
LCDM_DATA_PORT =temp;
SEN();
asm("nop");
asm("nop");
CEN();
}
/***********************************************************/
/***********************************************************/
void lcd_command_write(uchar temp)
{
while(lcd_check_busy())
{
asm("nop");
}
LCDM_DATA_DDR =0xff;
LCDM_DATA_PORT=0x0;
CRS();
CRW();
LCDM_DATA_PORT=temp;
SEN();
asm("nop");
asm("nop");
CEN();
}
/***********************************************************/
/***********************************************************/
void lcd_set_xy(uchar x,uchar y)
{
uchar address;
switch(y)
{
case 0:
address = 0x80 + x;
break;
case 1:
address = 0x90 + x;
break;
case 2:
address = 0x88 + x;
break;
case 3:
address = 0x98 + x;
break;
default:address = 0x80 + x;
}
lcd_command_write(address);
}
/***********************************************************/
/***********************************************************/
void lcd_write_string(unsigned char x,unsigned char y,const char *s)
{
lcd_command_write(0x30);
lcd_set_xy(x,y);
while (*s)
{
lcd_data_write(*s);
s++;
}
}
//=======================================================================
void lcd_clear_ddram(void)
{
lcd_command_write(0x30);
lcd_command_write(0x01);
}
/***********************************************************/
/***********************************************************/
void lcd_clear_gdram(void)
{
uchar line,row; //行,列
lcd_command_write(lcd_funtion_additional); //扩展指令集
//
lcd_command_write(lcd_move_select); //允许设定cgram地址
lcd_command_write(lcd_funtion_additional|0x04); //关cgram显示
//
for(line=0;line<32;line++) //64*32*8点
{
lcd_command_write(line|0x80); //设置绘图区的Y地址坐标 //Y地址加1
lcd_command_write(0x80); //设置绘图区的X地址坐标
for(row=32;row>0;row--)
{
lcd_data_write(0x0);
}
}
}
/***********************************************************/
/***********************************************************/
void lcd_init(void)
{
conport_init();
CRS();
CRW();
CEN();
delay_nms(1);
lcd_command_write(0x30);
lcd_command_write(0x0c);
lcd_command_write(0x01);
lcd_command_write(0x02);
lcd_command_write(0x80);
}
/***********************************************************/
/***********************************************************/
void lcd_clean()
{
lcd_command_write(0x01);
lcd_command_write(0x34);
lcd_command_write(0x30);
}
/***********************************************************/
/***********************************************************/
void lcd_oppose(uchar x)
{
lcd_command_write(0x34);
lcd_command_write(0x04|x);
}
/***********************************************************/
/***********************************************************/
void display_pic(const uchar *s)
{
COUNT3=0X02;
LCD_X=0X80;
for (;COUNT3!=0;COUNT3--)
{
LCD_Y=0X80;
COUNT2=0X20;//32
for (;COUNT2!=0;COUNT2--)
{
COUNT1=0X10;//16
lcd_command_write(0x34);
lcd_command_write(LCD_Y);
lcd_command_write(LCD_X);
lcd_command_write(0x30);
for (;COUNT1!=0;COUNT1--)
{
lcd_data_write(*s++);
}
LCD_Y+=1;
}
LCD_X=0X88;
}
lcd_command_write(0x36);
lcd_command_write(0x30);
}
/***********************************************************/
/***********************************************************/
void lcd_write_spot(uchar x,uchar y)
{
uchar address_x=0,address_y=0;//X,Y轴坐标
uchar temp_x=0,temp_xx=0,temp_xxx=0,temp_y=0;
uchar last_ram=0;
temp_y=y/16;
switch(temp_y)
{
case 0:temp_x=0x80;break;
case 1:temp_x=0x90;break;
case 2:temp_x=0x88;break;
case 3:temp_x=0x98;break;
default:temp_x=0x80;break;
}
temp_xx=x/16;
switch(temp_xx)
{
case 0:temp_xxx=0;break;
case 1:temp_xxx=1;break;
case 2:temp_xxx=2;break;
case 3:temp_xxx=3;break;
case 4:temp_xxx=4;break;
case 5:temp_xxx=5;break;
case 6:temp_xxx=6;break;
case 7:temp_xxx=7;break;
default:temp_xxx=0;break;
}
address_x=temp_x+temp_xxx;
if(y>31)y-=32;
address_y=y+0x80;
lcd_command_write(0x30); //基本指令
lcd_set_xy(0,0);
last_ram=lcd_data_read();
lcd_command_write(0x34);//扩展指令
lcd_command_write(address_y);//LCD_Y
lcd_command_write(address_x);//LCD_x
lcd_command_write(0x30); //基本指令
switch(x-temp_xxx*16)
{
//画点,高位
//画点.低位
case 0:lcd_data_write(0x80|last_ram);break;
case 1:lcd_data_write(0x40|last_ram);break;
case 2:lcd_data_write(0x20|last_ram);break;
case 3:lcd_data_write(0x10|last_ram);break;
case 4:lcd_data_write(0x08|last_ram);break;
case 5:lcd_data_write(0x04|last_ram);break;
case 6:lcd_data_write(0x02|last_ram);break;
case 7:lcd_data_write(0x01|last_ram);break;
case 8:lcd_data_write(0x00);lcd_data_write(0x80|last_ram);break;
case 9:lcd_data_write(0x00);lcd_data_write(0x40|last_ram);break;
case 10:lcd_data_write(0x00);lcd_data_write(0x20|last_ram);break;
case 11:lcd_data_write(0x00);lcd_data_write(0x10|last_ram);break;
case 12:lcd_data_write(0x00);lcd_data_write(0x08|last_ram);break;
case 13:lcd_data_write(0x00);lcd_data_write(0x04|last_ram);break;
case 14:lcd_data_write(0x00);lcd_data_write(0x02|last_ram);break;
case 15:lcd_data_write(0x00);lcd_data_write(0x01|last_ram);break;
default:lcd_data_write(0x00);break;
}
lcd_command_write(0x36);//开显示
}
void reverse_logo(uchar x,uchar y,uchar number)
{// lcd_clear_gdram();
uint i,j;
uchar address_x=0,address_y=0;//X,Y轴坐标
address_x=0x80+x;
address_y=0x80+y*16;
for(i=0;i<16;i++)
{
lcd_command_write(0x34);//扩展指令
lcd_command_write(address_y);//LCD_Y
lcd_command_write(address_x);//LCD_x
lcd_command_write(0x30);
for(j=0;j<number;j++)
{
lcd_data_write(0xff);
lcd_data_write(0xff);
}
address_y++;
}
lcd_command_write(0x36);
lcd_command_write(0x30);
}
//==========================================================================================
//
//==========================================================================================
void drawf(uchar xs,uchar ys,uchar xe,uchar ye)
{
uchar i,j;
for(j=ys;j<=ye;j++)
{if(j==ys|j==ye)
{
for(i=xs;i<=xe;i++)
{
lcd_write_spot(i,j);
}
}
else
{
lcd_write_spot(xs,j);
lcd_write_spot(xe,j);
}
}
}
//=================================================================================================================
//=================================================================================================================
void irinit()
{
DDRB|=_BV(PB6);
TCCR1B=0;
TCCR1B|=_BV(ICNC1)|_BV(CS11)|_BV(CS10);
TIMSK|=_BV(TICIE1);
sei();
}
SIGNAL(SIG_INPUT_CAPTURE1)
{//PORTC=0XFF;
TCNT1=0;
capturetime=ICR1;
if(capturetime<155&&capturetime>135)
;
else if(capturetime<290&&capturetime>270)
{
temp|=(1<<(time-16));
}
else
{temp=0;
time=0;
return;
}
time++;
if(time==32)
{
time=0;
sigtem=temp/256;
PORTC=sigtem;
temp=0;
}
}
//===============================================================================================
int main()
{
lcd_init();
conport_init();
irinit();
DDRC=0XFF;
while(1)
{
/*if(sigtem==0xf7)
{down++;
sigtem=0;
if(down==4)
down=0;
}*/
delay_nms(100);
lcd_clear_gdram();
lcd_write_string(0,0,"1.磁场");
lcd_write_string(0,1,"2.时间");
lcd_write_string(0,2,"3.温度");
lcd_write_string(0,3,"4.设置");
reverse_logo(0,2,3);
reverse_logo(0,1,3);
//drawf(50,50,60,60);
//display_pic( welcomeScreen);
while(1);
//lcd_write_spot(30,50);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -