?? ocmj4x8b(avr).c
字號:
/***********************
型號:OCMJ4X8B
單片機:ATmega8
內(nèi)部RC振蕩:4M
編寫人:肇慶金鵬電子 吳英生 0758-2317972
日期:2007/1/5
修改紀(jì)錄:
***********************/
#include <iom8v.h>
#include <macros.h>
#define data_ora PORTB //MCU PROTB<------> LCM
#define uchar unsigned char
#define uint unsigned int
#define sbit(x,y) (x|=(1<<y)) //Set Bit y of Byte x
#define cbit(x,y) (x&=~(1<<y)) //Clear Bit y of Byte x
#define chkbit(x,y) (x&(1<<y)) //Check Bit y of Byte x
#define invbit(x,y) (x^=(1<<y)) //Invert Bit y of Byte x
#define busy PORTD //PORTD0 H:已收到數(shù)據(jù)并在處理中,L:空閑可接收數(shù)據(jù)
#define req PORTD //PORTD1 請求信號,H有效
const uchar chn[]={
"本系列中文模塊內(nèi)"
"置二級字庫,可在"
"任意位置反白顯示"
"使用更方便更靈活"
};
const uchar eng[]={
"Golden Palm TECH"
"TEL:0758-2263858"
" No.31 Jianshe "
"Road3 Zhaoqing "
"P.R.China "
"Postcode: 526040"
};
const uchar pic[]={
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x20,0x81,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x61,0x83,0x00,0xE0,0x00,0x00,0x0F,0xFF,0xE0,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0xE3,0x87,0x03,0xE0,0x00,0x00,0xFF,0xFF,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,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0x9F,0xC6,0x00,0x00,0x01,
0x80,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x7F,0xFF,0x9F,0x0C,0x00,0x00,0x01,
0x80,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x7F,0xFE,0x1E,0x0C,0x00,0x00,0x01,
0x80,0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x7F,0xFE,0x1E,0x0C,0x00,0x00,0x01,
0x80,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x7F,0xFE,0x1C,0x0C,0x00,0x00,0x01,
0x80,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0xFE,0xFC,0x18,0x0C,0x00,0x00,0x01,
0x80,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xE0,0xF8,0xF8,0x10,0x08,0x00,0x00,0x01,
0x80,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xE0,0xF9,0xF0,0x10,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0x21,0xF1,0xC0,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFE,0x21,0x81,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFE,0x11,0x01,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x01,0xFF,0xFE,0x7F,0xFE,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x7F,0xF8,0x3F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x1F,0xF0,0x0F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x07,0xE6,0x03,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x03,0xE0,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x01,0xC0,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x01,0xC0,0x00,0x64,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x03,0xE0,0x00,0x3A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x06,0x20,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x0C,0x20,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x31,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0xE1,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x01,0xFF,0xC1,0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x03,0xFA,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
};
/*****1us延時函數(shù)****/
void delay_1us(void)
{
asm("nop");
}
/****Nus延時函數(shù)****/
void delay(uint n)
{
uint i=0;
for (i=0;i<n;i++)
delay_1us();
}
/****1ms延時函數(shù)****/
void delay_1ms(void)
{
uint i;
for (i=0;i<1140;i++);
}
/****Nms延時函數(shù)****/
void delay1(uint n)
{
uint i=0;
for (i=0;i<n;i++)
delay_1ms();
}
/*******IO口初始化******/
void port_init(void)
{
PORTB=0xff;
DDRB=0xff;
PORTD=0xff;
DDRD=0xfe;
}
/***********顯示圖形***********/
void disp_img (const uchar *img)
{
uchar i,j;
for(j=0;j<64;j++)
{
for(i=4;i<20;i++)
{
wr_zb(0xf3,i,j);
send(img[j*16+i-4]);
}
}
}
/*----------顯示中文----------*/
void disp_chn (const uchar *chn)
{
uchar i,j;
for(j=0;j<4;j++)
{
for(i=2;i<10;i++)
{
wr_zb(0xf0,i,j);
send(chn[j*16+(i-2)*2]-0xa0);
send(chn[j*16+(i-2)*2+1]-0xa0);
}
}
}
/*------顯示字符(8X16點陣)-----*/
void disp_eng (const uchar *eng)
{
uchar i,j;
for(j=0;j<4;j++)
{
for(i=4;i<20;i++)
{
wr_zb(0xf9,i,j*16);
send(eng[j*16+i-4]);
}
}
}
/*------------寫命令或數(shù)據(jù)到LCD--------------*/
void wr_zb (uchar comm,uchar addr_x,uchar addr_y)
{
send(comm);
send(addr_x);
send(addr_y);
}
/*----寫命令或數(shù)據(jù)------*/
void send (uchar dat)
{
while(chkbit(PIND,PIND0));
data_ora=dat;
sbit(req,PORTD1);
while(!chkbit(PIND,PIND0));
cbit(req,PORTD1);
}
/*+++++++++主程序++++++++++*/
void main ()
{
CLI();
MCUCR=0x00;
GICR=0x00;
TIMSK=0x00; //timer interrupt sources
port_init();
cbit(req,PORTD1);
sbit(busy,PORTD0);
while(1)
{
send(0xf4);
disp_chn(chn);
delay1(800);
send(0xf4);
disp_eng(eng);
delay1(800);
send(0xf4);
disp_img(pic);
delay1(800);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -