nokia3310.h:
=============================================
#include <util/delay.h>
#include <avr/pgmspace.h>
#define sce_1() PORTB|=_BV(PB1) //片选
#define sce_0() PORTB&=~_BV(PB1) //片选
#define res_1() PORTB|=_BV(PB0) //复位,0复位
#define res_0() PORTB&=~_BV(PB0) //复位,0复位
#define dc_1() PORTD|=_BV(PD7) //1写数据,0写指令
#define dc_0() PORTD&=~_BV(PD7) //1写数据,0写指令
#define clk_1() PORTD|=_BV(PD5) //1写数据,0写指令
#define clk_0() PORTD&=~_BV(PD5) //1写数据,0写指令
#define d_1() PORTD|=_BV(PD6) //1写数据,0写指令
#define d_0() PORTD&=~_BV(PD6) //1写数据,0写指令
#define INT8U unsigned char;
#define INT16U unsigned int;
unsigned char vs[6][84]={"","","","","",""};
unsigned char hzbuf[16];
const prog_uchar D35[]={
0x1f,0x11,0x1f, //0 竖向排列,使用高5位
0x00,0x00,0x1f, //1 竖向排列,使用高5位
0x1d,0x15,0x17, //2
0x15,0x15,0x1f, //3
0x07,0x04,0x1f, //4
0x17,0x15,0x1d, //5
0x1f,0x15,0x1d, //6
0x01,0x01,0x1f, //7
0x1f,0x15,0x1f, //8
0x17,0x15,0x1f, //9
0x00,0x0a,0x00, //: :
0x00,0x04,0x00, //. ;
0x00,0x00,0x00 // <
//0,1,2,3,4,5,6,7,8,9,0,.,
};
//5*8字符
const prog_uchar data[]={
0x00, 0x00, 0x00, 0x00, 0x00, // sp
0x00, 0x00, 0x2f, 0x00, 0x00, // !
0x00, 0x07, 0x00, 0x07, 0x00, // "
0x14, 0x7f, 0x14, 0x7f, 0x14, // #
0x24, 0x2a, 0x7f, 0x2a, 0x12, // $
0x62, 0x64, 0x08, 0x13, 0x23, // %
0x36, 0x49, 0x55, 0x22, 0x50, // &
0x00, 0x05, 0x03, 0x00, 0x00, // ’
0x00, 0x1c, 0x22, 0x41, 0x00, // (
0x00, 0x41, 0x22, 0x1c, 0x00, // )
0x14, 0x08, 0x3E, 0x08, 0x14, // *
0x08, 0x08, 0x3E, 0x08, 0x08, // +
0x00, 0x00, 0xA0, 0x60, 0x00, // ,
0x08, 0x08, 0x08, 0x08, 0x08, // -
0x00, 0x60, 0x60, 0x00, 0x00, // .
0x20, 0x10, 0x08, 0x04, 0x02, // /
0x3E, 0x51, 0x49, 0x45, 0x3E, // 0
0x00, 0x42, 0x7F, 0x40, 0x00, // 1
0x42, 0x61, 0x51, 0x49, 0x46, // 2
0x21, 0x41, 0x45, 0x4B, 0x31, // 3
0x18, 0x14, 0x12, 0x7F, 0x10, // 4
0x27, 0x45, 0x45, 0x45, 0x39, // 5
0x3C, 0x4A, 0x49, 0x49, 0x30, // 6
0x01, 0x71, 0x09, 0x05, 0x03, // 7
0x36, 0x49, 0x49, 0x49, 0x36, // 8
0x06, 0x49, 0x49, 0x29, 0x1E, // 9
0x00, 0x36, 0x36, 0x00, 0x00, // :
0x00, 0x56, 0x36, 0x00, 0x00, // ;
0x08, 0x14, 0x22, 0x41, 0x00, // <
0x14, 0x14, 0x14, 0x14, 0x14, // =
0x00, 0x41, 0x22, 0x14, 0x08, // >
0x02, 0x01, 0x51, 0x09, 0x06, // ?
0x32, 0x49, 0x59, 0x51, 0x3E, // @
0x7C, 0x12, 0x11, 0x12, 0x7C, // A
0x7F, 0x49, 0x49, 0x49, 0x36, // B
0x3E, 0x41, 0x41, 0x41, 0x22, // C
0x7F, 0x41, 0x41, 0x22, 0x1C, // D
0x7F, 0x49, 0x49, 0x49, 0x41, // E
0x7F, 0x09, 0x09, 0x09, 0x01, // F
0x3E, 0x41, 0x49, 0x49, 0x7A, // G
0x7F, 0x08, 0x08, 0x08, 0x7F, // H
0x00, 0x41, 0x7F, 0x41, 0x00, // I
0x20, 0x40, 0x41, 0x3F, 0x01, // J
0x7F, 0x08, 0x14, 0x22, 0x41, // K
0x7F, 0x40, 0x40, 0x40, 0x40, // L
0x7F, 0x02, 0x0C, 0x02, 0x7F, // M
0x7F, 0x04, 0x08, 0x10, 0x7F, // N
0x3E, 0x41, 0x41, 0x41, 0x3E, // O
0x7F, 0x09, 0x09, 0x09, 0x06, // P
0x3E, 0x41, 0x51, 0x21, 0x5E, // Q
0x7F, 0x09, 0x19, 0x29, 0x46, // R
0x46, 0x49, 0x49, 0x49, 0x31, // S
0x01, 0x01, 0x7F, 0x01, 0x01, // T
0x3F, 0x40, 0x40, 0x40, 0x3F, // U
0x1F, 0x20, 0x40, 0x20, 0x1F, // V
0x3F, 0x40, 0x38, 0x40, 0x3F, // W
0x63, 0x14, 0x08, 0x14, 0x63, // X
0x07, 0x08, 0x70, 0x08, 0x07, // Y
0x61, 0x51, 0x49, 0x45, 0x43, // Z
0x00, 0x7F, 0x41, 0x41, 0x00, // [
0x55, 0x2A, 0x55, 0x2A, 0x55, // 55
0x00, 0x41, 0x41, 0x7F, 0x00, // ]
0x04, 0x02, 0x01, 0x02, 0x04, // ^
0x40, 0x40, 0x40, 0x40, 0x40, // _
0x00, 0x01, 0x02, 0x04, 0x00, // ’
0x20, 0x54, 0x54, 0x54, 0x78, // a
0x7F, 0x48, 0x44, 0x44, 0x38, // b
0x38, 0x44, 0x44, 0x44, 0x20, // c
0x38, 0x44, 0x44, 0x48, 0x7F, // d
0x38, 0x54, 0x54, 0x54, 0x18, // e
0x08, 0x7E, 0x09, 0x01, 0x02, // f
0x18, 0xA4, 0xA4, 0xA4, 0x7C, // g
0x7F, 0x08, 0x04, 0x04, 0x78, // h
0x00, 0x44, 0x7D, 0x40, 0x00, // i
0x40, 0x80, 0x84, 0x7D, 0x00, // j
0x7F, 0x10, 0x28, 0x44, 0x00, // k
0x00, 0x41, 0x7F, 0x40, 0x00, // l
0x7C, 0x04, 0x18, 0x04, 0x78, // m
0x7C, 0x08, 0x04, 0x04, 0x78, // n
0x38, 0x44, 0x44, 0x44, 0x38, // o
0xFC, 0x24, 0x24, 0x24, 0x18, // p
0x18, 0x24, 0x24, 0x18, 0xFC, // q
0x7C, 0x08, 0x04, 0x04, 0x08, // r
0x48, 0x54, 0x54, 0x54, 0x20, // s
0x04, 0x3F, 0x44, 0x40, 0x20, // t
0x3C, 0x40, 0x40, 0x20, 0x7C, // u
0x1C, 0x20, 0x40, 0x20, 0x1C, // v
0x3C, 0x40, 0x30, 0x40, 0x3C, // w
0x44, 0x28, 0x10, 0x28, 0x44, // x
0x1C, 0xA0, 0xA0, 0xA0, 0x7C, // y
0x44, 0x64, 0x54, 0x4C, 0x44, // z
0x00, 0x08, 0x36, 0x41, 0x00, // {
0x00, 0x00, 0x7F, 0x00, 0x00, // |
0x00, 0x41, 0x36, 0x08, 0x00, // }
0x08, 0x10, 0x08, 0x04, 0x08 // ~
};
const prog_uchar hz16[][32]={
{0x00,0x00,0x00,0x00,0xC0,0xF0,0xBC,0x8E,0x8E,0xBC,0xF0,0xC0,0x00,0x00,0x00,0x00,0x00,0x08,0x0C,0x0F,0x0B,0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x0F,0x0C,0x08,0x00},/*"A",0*/
{0x00,0x00,0x00,0x02,0xFE,0xFE,0x42,0x42,0x42,0x42,0xE2,0xBE,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x08,0x08,0x08,0x08,0x0F,0x07,0x00,0x00,0x00},/*"B",1*/
{0x00,0x00,0x00,0xF8,0xFC,0x06,0x02,0x02,0x02,0x02,0x06,0x0C,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x07,0x0C,0x08,0x08,0x08,0x08,0x0C,0x06,0x02,0x00,0x00,0x00}/*"C",2*/
};
/*--------------------------------------------
LCD_write_byte: 使用SPI接口写数据到LCD
输入参数:dt:写入的数据;
command :写数据/命令选择;
编写日期:20080918
----------------------------------------------*/
void LCD_write_byte(unsigned char dt)
{ unsigned char i,j;
sce_0();
//SPDR=dt; //开始发送数据
//while((SPSR>>7)==0); //等待发送接收结束
for (i=0x80;i!=0x00;i>>=1)
{ clk_0();
if (dt&i)
{ d_1();
}
else
{ d_0();
}
clk_1();
}
for (j=0;j<10;j++);
sce_1();
//PORTB=dt;
}
/*---------------------------------------
LCD_init: 3310LCD初始化
编写日期:20080918
----------------------------------------- */
void LCD_init(void)
{
/*res_0();
_delay_ms(1);
res_1();
dc_0();
LCD_write_byte(0x21);//初始化Lcd,功能设定使用扩充指令
LCD_write_byte(0xD0);//设定液晶偏置电压
LCD_write_byte(0x20);//使用基本指令
LCD_write_byte(0x0C);//设定显示模式,正常显示
dc_1();
*/
res_1();
sce_1();
_delay_ms(1);
res_0();
_delay_ms(1);
res_1();
dc_0();
LCD_write_byte(0x21);//初始化Lcd,功能设定使用扩充指令
LCD_write_byte(0xD0);//设定液晶偏置电压
LCD_write_byte(0x20);//使用基本指令
LCD_write_byte(0x0C);//设定显示模式,正常显示
dc_1();
}
/*-------------------------------------------
LCD_set_XY: 设置LCD坐标函数
输入参数:X:0-83 Y:0-5
编写日期:20080918
---------------------------------------------*/
void LCD_set_XY(unsigned char x, unsigned char y)
{
dc_0();
LCD_write_byte(0x80 | x);
LCD_write_byte(0x40 | y);
dc_1();
}
/*------------------------------------------
LCD_clear: LCD清屏函数
编写日期:20080918
--------------------------------------------*/
void LCD_clear(void)
{
unsigned char t;
unsigned char k;
LCD_set_XY(0,0);
dc_1();
for(t=0;t<6;t++)
{
for(k=0;k<84;k++)
{
LCD_write_byte(0x00);
}
}
}
void LCD_write_zifu(unsigned int x, unsigned int y,unsigned char dd) //x:x坐标 y:y坐标 dd:字符
{
unsigned char i=0;
unsigned int No;
No=dd-32; //字模数据是由空格开始,空格字符的ASCII的值就是32
No*=5;
LCD_set_XY(x,y);
dc_1();
while(i<5) //一个字符的字模是5个字节,就是5*8点阵
{
LCD_write_byte(pgm_read_byte(data+No));
i++;
No++;
}
}
/*---------------------------------------------
LCD_write_shu: 显示8(宽)*16(高)点阵列数字字母符号等半角类
输入参数:c:显示的字符;
编写日期:20080918
-----------------------------------------------*/
/*void LCD_write_zifustr(unsigned int x, unsigned int y,unsigned char *string,unsigned int l) //x:x坐标 y:y坐标 dd:字符
{
unsigned char i=0;
while(i<l)
{
LCD_write_zifu(x,y,string[i]); //顺序显示字符
i++;
x=x+7;
}
}
*/
void LCD_Wstr(unsigned int x, unsigned int y,unsigned char *string) //x:x坐标 y:y坐标 dd:字符
{
unsigned char i=0;
unsigned char j=0;
while(j==0)
{
if (string[i]==0)
{ j=1;
}
else
{ LCD_write_zifu(x,y,string[i]); //顺序显示字符
}
i++;
x=x+7;
}
}
/*
void LCD_write_hanzi(unsigned int x, unsigned int y,unsigned int dd) //x:x坐标 y:y坐标 dd:字符
{
unsigned char i=0;
LCD_set_XY(x,y);
dc_1();
dd=dd*24;
while(i<12)
{
LCD_write_byte(hanzi[dd]);
i++;
dd++;
}
LCD_set_XY(x,y+1);
while(i<24)
{
LCD_write_byte(hanzi[dd]);
i++;
dd++;
}
}
*/
//=================================================================================================
void clrVS() //清除缓存区
{ unsigned char t;
unsigned char k;
for(t=0;t<6;t++)
{
for(k=0;k<84;k++)
{
vs[t][k]=0;
}
}
}
void reflash() //刷新屏幕
{ unsigned char t;
unsigned char k;
LCD_set_XY(0,0);
dc_1();
for(t=0;t<6;t++)
{
for(k=0;k<84;k++)
{
LCD_write_byte(vs[t][k]);
}
}
}
void set(unsigned char x,unsigned char y,unsigned char c) //画一个点
{ unsigned char vy,vh,v;
vy=y/8;
vh=y&7;
if (c==0)
{ v=_BV(vh)^0xff;
vs[vy][x]&=v;
}
else
{ vs[vy][x]|=_BV(vh);
}
}
void h_line(unsigned char x1,unsigned char y,unsigned char x2,unsigned char c)
{ unsigned char i;
for (i=x1;i<=x2;i++)
{ set(i,y,c);
}
}
void D35A(unsigned char x,unsigned char y,unsigned char n) //输出一个3*5字符,输出必须4点间隔
{ unsigned char vy,vh,i,v,vv;
vy=y/8;
vh=y&7;
if (n<48) return;
if (n>60) return;
n=n-48;
n=n*3;
//画第一行
for (i=0;i<3;i++)
{ v=pgm_read_byte(D35+n+i);
v=v<<vh;
vv=0x1f;
vv=vv<<vh;
vv=vv^0xff;
vs[vy][x+i]&=vv;
vs[vy][x+i]|=v;
}
if (vh>=3)
{ //双行,还需补第二行
vy++;vh=8-vh;
for (i=0;i<3;i++)
{ v=pgm_read_byte(D35+n+i);
v=v>>vh;
vv=0x1f;
vv=vv>>vh;
vv=vv^0xff;
vs[vy][x+i]&=vv;
vs[vy][x+i]|=v;
}
}
}
void LCD_WDA35(unsigned char x, unsigned char y,unsigned char *string) //x:x坐标 y:y坐标 dd:字符
{
unsigned char i=0;
unsigned char j=0;
while(j==0)
{ D35A(x,y,string[i]); //顺序显示字符
i++;
if (string[i]==0) j=1;
x=x+4;
}
}
void D57A(unsigned char x,unsigned char y,unsigned int n) //输出一个5*7字符
{ unsigned char vy,vh,i,v,vv;
vy=y/8;
vh=y&7;
n=n-32;
n=n*5;
//画第一行
for (i=0;i<5;i++)
{ v=pgm_read_byte(data+n+i);
v=v<<vh;
vv=0xff;
vv=vv<<vh;
vv=vv^0xff;
vs[vy][x+i]&=vv;
vs[vy][x+i]|=v;
}
if (vh>0)
{ //双行,还需补第二行
vy++;vh=8-vh;
for (i=0;i<5;i++)
{ v=pgm_read_byte(data+n+i);
v=v>>vh;
vv=0xff;
vv=vv>>vh;
vv=vv^0xff;
vs[vy][x+i]&=vv;
vs[vy][x+i]|=v;
}
}
}
void LCD_WDA57(unsigned char x, unsigned char y,unsigned char *string) //x:x坐标 y:y坐标 dd:字符
{
unsigned char i=0;
unsigned char j=0;
while(j==0)
{ D57A(x,y,string[i]); //顺序显示字符
i++;
if (string[i]==0) j=1;
x=x+6;
}
}
void D16HZ(unsigned char x,unsigned char y,unsigned char n) //输出一个16点阵汉字,要求 y%8=0
{ unsigned char vy,i,v,xx,vv;
y&=0xf8; //如果y不在4位格上,强行置位
vy=y/8;
n--;
for (i=0;i<16;i++)
{ xx=x+i;
vs[vy][xx]=pgm_read_byte(&hz16[n][i]);
vs[vy+1][xx]=pgm_read_byte(&hz16[n][i+16]);
}
}
void LCD_WHZ16(unsigned char x, unsigned char y) //x:x坐标 y:y坐标 dd:字符
{
unsigned char i=0;
unsigned char j=0;
while(j==0)
{ D16HZ(x,y,hzbuf[i]); //顺序显示字符
i++;
if (hzbuf[i]==0) j=1;
x=x+16;
}
} |