|
那位兄弟帮看哈~ 就请个屏,显示一个"!"
/***************************************************************
****************************************************************/
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include "string.h"
#include "stdlib.h"
#include <avr/wdt.h>
#include <avr/eeprom.h>
#include <avr/delay.h>
#define NOP asm volatile("nop
"::)
#define LED 5
#define Light 3 //PC3
#define CD 2 //PC2
#define RD 1 //PC1
#define WR 0 //PC0
#define LineChar 30
const unsigned char TABLE_ASCII[]=
{
0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,
0x10,0x10,0x00,0x00,0x18,0x18,0x00,0x00 //;!
};
//--------------------------------------------------------------------------
void init_port(void);
void init_timer1(void);
unsigned char readstate(void);
void st01(void);
void st2(void);
void st3(void);
void writecode(unsigned char cmd);
void writedata(unsigned char data);
void writeauto(unsigned char data);
void oneparameter(unsigned char op1,unsigned char cmd);
void twoparameter(unsigned char op1,unsigned char op2,unsigned char cmd);
void lcd_init(void);
void lcd_clear(void);
void writeasc(unsigned char x,unsigned char y,unsigned char asc);
unsigned int r_lightdelay=0;
int main(void)
{
cli();
MCUSR=0;
wdt_disable();
init_port();
init_timer1();
lcd_init();
lcd_clear();
_delay_ms(20);
writeasc(0,0,'1');
sei();
while(1)
{
};
}
void init_port(void)
{
PORTB=0b11111111; //
DDRB=0b00101111; //SCK MOSI SS输出 MISO输入
PORTC=0xFF;
DDRC=0XFF; //
PORTD=0xFF;
DDRD=0xFF; //UI1~UI6输出
}
void init_timer1(void)
{
TCCR1A=0;
TCCR1B= (1<<CS12); //256预分频 晶振为7.3728MHz 一条指令大约34.72us
TCNT1=65535-((7372800/256)*50)/1000; //50ms中断初值
TIMSK1=(1<<TOIE1); //中断允许
}
SIGNAL(SIG_OVERFLOW1) //T1中断
{
TCNT1=65535-((7372800/256)*50)/1000;
r_lightdelay++;
if (r_lightdelay>=40)
{
r_lightdelay=0;
PORTC^=(1<<LED);
}
}
unsigned char readstate(void)
{
unsigned char lcd_state;
DDRD=0x00;
PORTD=0XFF;
PORTC|=(1<<CD);
NOP;
PORTC&=~(1<<RD);
lcd_state=PIND&0xff;
NOP;
NOP;
PORTC|=(1<<RD);
DDRD=0xFF;
return lcd_state;
}
void st01(void)
{
while((readstate()&0x03)!=3);
}
void st2(void)
{
while((readstate()&0x04)!=4);
}
void st3(void)
{
while((readstate()&0x08)!=8);
}
//指令写入函数
void writecode(unsigned char cmd)
{
st01();
PORTD=cmd;
PORTC&=~(1<<WR);
NOP;
PORTC|=(1<<WR);
}
//数据写入函数
void writedata(unsigned char data)
{
st01();
PORTC&=~(1<<CD);
NOP;
PORTD=data;
PORTC&=~(1<<WR);
NOP;
PORTC|=(1<<WR);
}
//数据自动写入函数
void writeauto(unsigned char data)
{
st3();
PORTC&=~(1<<CD);
NOP;
PORTD=data;
PORTC&=~(1<<WR);
NOP;
PORTC|=(1<<WR);
}
void oneparameter(unsigned char op1,unsigned char cmd)
{
writedata(op1);
writecode(cmd);
}
void twoparameter(unsigned char op1,unsigned char op2,unsigned char cmd)
{
writedata(op1);
writedata(op2);
writecode(cmd);
}
void lcd_init(void)
{
twoparameter(0x00,0x00,0x40); //文本显示区域首地址
twoparameter(30,0x00,0x41); //文本显示区域宽度
twoparameter(0x00,0x00,0x42); //图形显示区域首地址
twoparameter(30,0x00,0x43); //图形显示区域宽度
writecode(0xa7); //光标形状
writecode(0x80); //显示方式设置,逻辑"或"合成
writecode(0x98); //显示开关设置
}
void lcd_clear(void)
{
unsigned int count;
twoparameter(0x00,0x00,0x24);
writecode(0xb0);
for(count=8192;count>0;count--)
writeauto(0x00);
writecode(0xb2);
}
void writeasc(unsigned char x,unsigned char y,unsigned char asc)
{
unsigned char i,dat;
unsigned int address;
address=x*LineChar+y;
for(i=0;i<16;i++)
{
dat=TABLE_ASCII;
twoparameter((unsigned char)address,(unsigned char)(address>>8),0x24);
oneparameter(dat,0xc4);
address+=LineChar;
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|