📄 1602b_lcd_test.c
字号:
#include <iom8v.h>
#include <macros.h>
#include <math.h>
#include "1602LCD.h"
const unsigned char table[]="0123456789";
const unsigned char love[]="I Love U,MeiMei!";
unsigned char h=0x0A,m=0x28,s=0x20,temp1;
unsigned char ch,ch1=0;
//TIMER1 initialize - prescale:1024
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 1Hz
// actual value: 1.000Hz (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xF0; //setup
TCNT1L = 0xBE;
OCR1AH = 0x0F;
OCR1AL = 0x42;
OCR1BH = 0x0F;
OCR1BL = 0x42;
ICR1H = 0x0F;
ICR1L = 0x42;
TCCR1A = 0x00;
TCCR1B = 0x04; //start Timer
}
#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{
//TIMER1 has overflowed
TCNT1H = 0xF0; //reload counter high value
TCNT1L = 0xBE; //reload counter low value
s++;
if(s>0x3B)
{s=0x0;
m++;}
if(m>0x3B)
{m=0x0;
h++;}
if(h>0x0C)
{h=0x0;}
write_s(s);
write_m(m);
write_h(h);
LCD_set_xy(ch,1);
LCD_write_char(0,love[ch1]);
ch++;
ch1++;
if(ch>15)
{ch=ch-16;
}
if(ch1>16)
{ch1=0;
ch=0;
LCD_write_string(0,1," ");}
}
void write_h(unsigned char h)
{ unsigned char temp=0;
LCD_set_xy(0,0);
temp=h/10;
LCD_write_char(0,table[temp]);
temp=h%10;
LCD_write_char(0,table[temp]);
LCD_write_char(0,':');
}
void write_m(unsigned char m)
{ unsigned char temp=0;
LCD_set_xy(3,0);
temp=m/10;
LCD_write_char(0,table[temp]);
temp=m%10;
LCD_write_char(0,table[temp]);
LCD_write_char(0,':');
}
void write_s(unsigned char s)
{ unsigned char temp=0;
LCD_set_xy(6,0);
temp=s/10;
LCD_write_char(0,table[temp]);
temp=s%10;
LCD_write_char(0,table[temp]);
}
void main(void)
{ unsigned char i=0b000001;
OSCCAL=0XBA;
DDRD |= LCD_DATA | LCD_RW;
DDRC |= LCD_RS | LCD_EN;
LCD_init();
LCD_write_char(0x01,0);
//stop errant interrupts until set up
CLI(); //disable all interrupts
timer1_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x04; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
LCD_set_xy(3,0);
LCD_set_xy(6,0);
LCD_write_char(0,':');
while(1)
{ ;}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -