本帖最后由 shi910229 于 2014-5-1 15:18 编辑
主函数:
#include "iom16a.h"
#include "init_mcu.h"
#include "LCD12864-S.h"
#include "keyboard&menu.h"
#include "data_processing.h"
#define set_bit(x,y) (x|=(1<<y))
#define clr_bit(x,y) (x&=~(1<<y))
extern char LCD12864_table1[17];
extern unsigned long int frequency_r_fix,frequency_c_fix,frequency_l_fix;
extern unsigned char key1num;
void main( void )
{
init_mcu();
LCD12864_init();
LCD12864_display();
set_bit(GICR,6);clr_bit(GICR,7);clr_bit(GICR,5);
while(1)
{
keyscan();
switch(key1num)
{
case 0:r_processing();break;
case 1:c_processing();break;
case 2:l_processing();break;
default :break;
}
LCD12864_display();
}
}
12864串口通信:
#include "iom16a.h"
#define set_bit(x,y) (x|=(1<<y))
#define clr_bit(x,y) (x&=~(1<<y))
#define LCD12864_SID_1 set_bit(PORTC,6)
#define LCD12864_SID_0 clr_bit(PORTC,6)
#define LCD12864_SCLK_1 set_bit(PORTC,7)
#define LCD12864_SCLK_0 clr_bit(PORTC,7)
char LCD12864_table1[17]={" RLC测量仪-R "};
char LCD12864_table2[17]={"换档:自动 "};
char LCD12864_table3[17]={"量程: "};
char LCD12864_table4[17]={"请稍等... "};
void LCD12864_delay1us(unsigned char LCD12864_us) //延时1us,16M/4T
{
unsigned int LCD12864_delay;
for(LCD12864_delay=0;LCD12864_delay<LCD12864_us;LCD12864_delay++)
{
unsigned char a,b;
for(b=1;b>0;b--)
for(a=1;a>0;a--);
}
}
void LCD12864_write_byte(unsigned char LCD12864_byte)
{
unsigned char LCD12864_i;
for(LCD12864_i=0;LCD12864_i<8;LCD12864_i++)
{
if(LCD12864_byte&0x80)LCD12864_SID_1;
else LCD12864_SID_0;
LCD12864_delay1us(20);
LCD12864_SCLK_1;
LCD12864_delay1us(20);
LCD12864_SCLK_0;
LCD12864_byte<<=1;
}
}
void LCD12864_write_comm(unsigned char LCD12864_comm)
{
unsigned char Scomm,Hcomm,Lcomm;
Scomm=0xf8; //写指令
Hcomm=LCD12864_comm&0xf0;
Lcomm=(LCD12864_comm<<4)&0xf0;
LCD12864_write_byte(Scomm);
LCD12864_delay1us(20);
LCD12864_write_byte(Hcomm);
LCD12864_delay1us(20);
LCD12864_write_byte(Lcomm);
LCD12864_delay1us(20);
}
void LCD12864_write_data(unsigned char LCD12864_data)
{
unsigned char Sdata,Hdata,Ldata;
Sdata=0xfa; //写数据
Hdata=LCD12864_data&0xf0;
Ldata=(LCD12864_data<<4)&0xf0;
LCD12864_write_byte(Sdata);
LCD12864_delay1us(20);
LCD12864_write_byte(Hdata);
LCD12864_delay1us(20);
LCD12864_write_byte(Ldata);
LCD12864_delay1us(20);
}
void LCD12864_init()
{
LCD12864_write_comm(0x30); //基本指令集
LCD12864_write_comm(0x02); //地址归位
LCD12864_write_comm(0x0c); //整体显示打开,游标关闭
LCD12864_write_comm(0x01); //清除显示
LCD12864_write_comm(0x06); //光标从右向左加一位移动
}
void LCD12864_display()
{
unsigned char LCD12864_i;
LCD12864_write_comm(0x80);
for(LCD12864_i=0;LCD12864_i<16;LCD12864_i++)
LCD12864_write_data(LCD12864_table1[LCD12864_i]);
LCD12864_write_comm(0x90);
for(LCD12864_i=0;LCD12864_i<16;LCD12864_i++)
LCD12864_write_data(LCD12864_table2[LCD12864_i]);
LCD12864_write_comm(0x88);
for(LCD12864_i=0;LCD12864_i<16;LCD12864_i++)
LCD12864_write_data(LCD12864_table3[LCD12864_i]);
LCD12864_write_comm(0x98);
for(LCD12864_i=0;LCD12864_i<16;LCD12864_i++)
LCD12864_write_data(LCD12864_table4[LCD12864_i]);
}
void LCD12864_display_line1()
{
unsigned char LCD12864_i;
LCD12864_write_comm(0x80);
for(LCD12864_i=0;LCD12864_i<16;LCD12864_i++)
LCD12864_write_data(LCD12864_table1[LCD12864_i]);
}
void LCD12864_display_line2()
{
unsigned char LCD12864_i;
LCD12864_write_comm(0x90);
for(LCD12864_i=0;LCD12864_i<16;LCD12864_i++)
LCD12864_write_data(LCD12864_table2[LCD12864_i]);
}
void LCD12864_display_line3()
{
unsigned char LCD12864_i;
LCD12864_write_comm(0x88);
for(LCD12864_i=0;LCD12864_i<16;LCD12864_i++)
LCD12864_write_data(LCD12864_table3[LCD12864_i]);
}
void LCD12864_display_line4()
{
unsigned char LCD12864_i;
LCD12864_write_comm(0x98);
for(LCD12864_i=0;LCD12864_i<16;LCD12864_i++)
LCD12864_write_data(LCD12864_table4[LCD12864_i]);
}
*
|