📄 essai.c
字号:
#include <avr/io.h>
#define F_CPU 4000000UL // 4 MHz
#include <util/delay.h>
#define LCD PORTC
unsigned char getkey(void)
{
unsigned char RES;
PORTD|=_BV(4);
_delay_us(10);
if (bit_is_set(PINB,0)) {RES="8";}
if (bit_is_set(PINB,1)) {RES="7";}
if (bit_is_set(PINB,2)) {RES="H";}
if (bit_is_set(PINB,3)) {RES="9";}
PORTD&=~_BV(4);
PORTD|=_BV(5);
_delay_us(10);
if (bit_is_set(PINB,0)) {RES="5";}
if (bit_is_set(PINB,1)) {RES="4";}
if (bit_is_set(PINB,2)) {RES="R";}
if (bit_is_set(PINB,3)) {RES="6";}
PORTD&=~_BV(5);
PORTD|=_BV(6);
_delay_us(10);
if (bit_is_set(PINB,0)) {RES="2";}
if (bit_is_set(PINB,1)) {RES="1";}
if (bit_is_set(PINB,2)) {RES="B";}
if (bit_is_set(PINB,3)) {RES="3";}
PORTD&=~_BV(6);
PORTD|=_BV(7);
_delay_us(10);
if (bit_is_set(PINB,0)) {RES="0";}
if (bit_is_set(PINB,1)) {RES="A";}
if (bit_is_set(PINB,2)) {RES=" ";}
if (bit_is_set(PINB,3)) {RES="E";}
PORTD&=~_BV(7);
return(RES);
}
void ecrit_instr_lcd(unsigned char instr)
{
unsigned char instr_tmp = 0x00;
LCD&=~_BV(0);
LCD|=_BV(1);
instr_tmp = instr;
instr_tmp &= 0xF0;
instr_tmp = instr_tmp>>2;
instr_tmp |= 0x02;
instr_tmp &= 0xFE;
LCD = instr_tmp;
_delay_us(400);
LCD&=~_BV(1);
instr_tmp=0x00;
LCD&=~_BV(0);
LCD|=_BV(1);
instr_tmp = instr;
instr_tmp &= 0x0F;
instr_tmp = instr_tmp<<2;
instr_tmp |= 0x02;
instr_tmp &= 0xFE;
LCD = instr_tmp;
_delay_us(400);
LCD&=~_BV(1);
}
void lcd_goto(unsigned char cell)
{
unsigned int i;
ecrit_instr_lcd (0x02);
for (i = 1; i < cell; i++)
{
ecrit_instr_lcd (0x14);
}
}
void ecrit_data_lcd(unsigned char data)
{
unsigned char data_tmp = 0x00;
LCD|=_BV(0);
LCD|=_BV(1);
data_tmp = data;
data_tmp &= 0xF0;
data_tmp = data_tmp>>2;
data_tmp |= 0x03;
LCD = data_tmp;
_delay_us(100); //modif 10ms
LCD&=~_BV(1);
data_tmp = 0x00;
LCD|=_BV(0);
LCD|=_BV(1);
data_tmp = data;
data_tmp &= 0x0F;
data_tmp = data_tmp<<2;
data_tmp |= 0x03;
LCD = data_tmp;
_delay_us(100);//modif 10ms
LCD&=~_BV(1);
}
void lcd_init(void)
{
_delay_ms(20);
LCD&=~_BV(0);
_delay_us(1);
LCD|=_BV(1);
LCD=0x0E;
_delay_ms(10);
LCD&=~_BV(1);
_delay_ms(5);
LCD&=~_BV(0);
_delay_us(1);
LCD|=_BV(1);
LCD=0x0E;
_delay_ms(10);
LCD&=~_BV(1);
_delay_ms(1);
LCD&=~_BV(0);
_delay_us(1);
LCD|=_BV(1);
LCD=0x0E;
_delay_ms(10);
LCD&=~_BV(1);
LCD&=~_BV(0);
_delay_us(1);
LCD|=_BV(1);
LCD=0x0A;
_delay_ms(10);
LCD&=~_BV(1);
ecrit_instr_lcd(0x28);
ecrit_instr_lcd(0x06);
ecrit_instr_lcd(0x0C);
ecrit_instr_lcd(0x01);
}
void lcd_clear(void)
{
ecrit_instr_lcd(0x01);
}
void lcd_puts(char *str)
{
while(*str != 0x00)
{
ecrit_data_lcd(*str++);
}
}
double temperature;
char *temperature_str="00.0";
int main(void)
{
//DDRA=0xFE;
//PORTA=0xFE;
DDRD=0xFF;
DDRB=0x00;
DDRC=0x3F;
//ADCSRA=0x85;
lcd_init();
lcd_clear();
ecrit_instr_lcd(0x80);
// ("L1-----------------+L3-0123456789ABCDEF+L2-0123456789ABCDEF+L4-0123456789ABCDEF+" );
// while(1)
// {
lcd_puts("===MENU PRINCIPAL===____________________T:0.00癈 H:0.00 1-Setup |08:00");
// _delay_ms(1000);
// lcd_puts("=======OPTION=======2-T Cons. 5- 1-Dat/Heu 4- 3-H Cons. 6-Retour");
// _delay_ms(1000);
// }
unsigned char CHb = "";
unsigned char CH = "";
while (1)
{
//ADMUX=0x00;
//ADCSRA|=_BV(6);
//while(bit_is_clear(ADCSRA, 4));
//ADCSRA|=_BV(4);
//temperature=(double)ADCW*50/1024;
//dtostrf(temperature,3,1,temperature_str);
//ecrit_instr_lcd(0x87);
//lcd_puts(temperature_str);
//ecrit_instr_lcd(0x8C);
//ecrit_data_lcd(0xDF);
//=============================ECRIRE TEXTE
//CH = "";
//CH =getkey();
//if (CH==""){CHb="1";}
//if (CH!=CHb){lcd_puts(CH); CHb="";}
//lcd_goto(50);
//CHb=CH;
unsigned char A = "";
A=getkey();
if (A == "1") {lcd_puts("=======OPTION=======2-T Cons. 5- 1-Dat/Heu 4- 3-H Cons. 6-Retour");}
_delay_ms(1);
}
return (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -