TXT

CODE

By Louise Webb,2014-10-31 18:25
23 views 0
CODE

    //====================================================== ////自编的全部程序文件包括!

    ////minilcd.h 12864lcd驱动

    ////minilcd.c "

    ////ds1302.h ds1302驱动

    ////ds1302.c "

    ////miniclock.h 字模数组

    ////miniclock.c 主程序

    //====================================================== //++++++++++++++++++++++++

    //======miniclock.h========

    // 字模表!88点阵,1216点阵数字,1616点阵汉字和小鸡图案

//================以下存放在FLASH

#include <avr/pgmspace.h>

//08数字

    const char num88[][8] PROGMEM={{0x00,0x7C,0xFE,0x82,0x82,0xFE,0x7C,0x00},

    {0x00,0x00,0x84,0xFE,0xFE,0x80,0x00,0x00},//1 {0x00,0xC4,0xC6,0xA2,0x92,0x9E,0xCC,0x00},//2 {0x00,0xC4,0xC6,0x92,0x92,0xFE,0x6c,0x00},//3 {0x00,0x60,0x50,0x48,0x44,0xFE,0xFE,0x40},//4 {0x00,0xDE,0xDE,0x8A,0x8A,0xFA,0x72,0x00},//5 {0x00,0x7C,0xFE,0x92,0x92,0xF6,0x76,0x00},//6 {0x00,0x06,0x06,0xC2,0xE2,0x1E,0x0E,0x00},//7 {0x00,0x6c,0xFE,0x92,0x92,0xFE,0x6c,0x00},//8 {0x00,0x5c,0xDE,0x92,0x92,0xFE,0x7c,0x00},//9 {0x00,0x78,0x24,0x22,0x22,0x24,0x78,0x00},//A {0x00,0x42,0x7E,0x4A,0x4A,0x4A,0x34,0x00},//B {0x00,0x3C,0x42,0x42,0x42,0x42,0x66,0x00},//C {0x00,0x42,0x7E,0x42,0x42,0x42,0x3C,0x00},//D {0x00,0x42,0x7E,0x4A,0x4A,0x42,0x66,0x00},//E {0x00,0x02,0x7E,0x12,0x12,0x12,0x02,0x00},//F {0x00,0x00,0x00,0xCC,0xCC,0x00,0x00,0x00},//- {0x00,0x00,0x30,0x30,0x30,0x30,0x00,0x00},//: {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; //SPACE

//12*16数字

    const char num1216[][24]

    PROGMEM={{0x00,0xFC,0xFE,0x06,0x06,0x86,0x46,0x26,0x16,0xFE,0xFC,0x00,0x00,0x3F,

    0x7F,0x68,0x64,0x62,0x61,0x60,0x60,0x7F,0x3F,0x00},//0 {0x00,0x00,0x00,0x00,0x08,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

    ,0x00,0x7F,0x7F,0x00,0x00,0x00,0x00,0x00}, //1

    {0x00,0x3C,0x3E,0x06,0x06,0x06,0x06,0x86,0xC6,0x7E,0x3C,0x00,0x00,0x60,0x70,0x78,0x6C,0x66,0x63,0x61,0x60,0x60,0x60,0x00}, //2

    {0x00,0x3C,0x3E,0x06,0x06,0xC6,0xC6,0xC6,0xC6,0xFE,0x3C,0x00,0x00,0x3C,0x7C,0x60,0x60,0x60,0x60,0x60,0x60,0x7F,0x3F,0x00}, //3

    {0x00,0x00,0x80,0xE0,0x78,0x1E,0x06,0xFE,0xFE,0x00,0x00,0x00,0x00,0x1E,0x1F,0x19,0x18,0x18,0x18,0x7F,0x7F,0x18,0x18,0x00}, //4

    {0x00,0xFE,0xFE,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0x86,0x00,0x00,0x3C,0x7C,0x60,0x60,0x60,0x60,0x60,0x60,0x7F,0x3F,0x00}, //5

    {0X00,0xFC,0xFE,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0xCE,0x8C,0x00,0x00,0x3F,0x7F,0x60,0x60,0x60,0x60,0x60,0x60,0x7F,0x3F,0x00}, //6

    {0x00,0x1E,0x1E,0x06,0x06,0x06,0x06,0x86,0xE6,0x7E,0x1E,0x00,0x00,0x00,0x00,0x00,0x60,0x78,0x1E,0x07,0x01,0x00,0x00,0x00}, //7

    {0x00,0x7C,0xFE,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0xFE,0x7C,0x00,0x00,0x3F,0x7F,0x60,0x60,0x60,0x60,0x60,0x60,0x7F,0x3F,0x00}, //8

    {0x00,0xFC,0xFE,0x06,0x06,0x06,0x06,0x06,0x06,0xFE,0xFC,0x00,0x00,0x31,0x73,0x63,0x63,0x63,0x63,0x63,0x63,0x7F,0x3F,0x00}, //9

    {0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00}, //-

    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //space

    {0x00,0x00,0x00,0x00,0x18,0x3C,0x3C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; //.

//小鸡图案

    const unsigned char chik1[32]

    PROGMEM={0x00,0x00,0x00,0x80,0x80,0x80,0x80,0xE0,0x70,0x18,0x18,0x18,0x18,0xF8,0xFC,0xCC,

    0x00,0x4E,0x31,0x20,0x24,0x10,0x19,0x19,0x16,0x90,0x50,0x70,0x78,0x5E,0x1F,0x07};//小鸡1

const unsigned char chik2[32]

    PROGMEM={0x80,0x80,0x40,0x20,0x20,0x20,0xC0,0xE0,0x70,0x18,0x18,0x18,0x18,0xF0,0xE0,0x60,

    0x01,0x03,0x04,0x09,0x08,0x18,0x50,0x59,0x76,0x90,0x50,0x70,0x78,0x5E,0x07,0x00};//小鸡2

//16*16汉字

    const unsigned char HANZ[][32]

    PROGMEM={{0x00,0x00,0x00,0xFE,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0xFF,0x02,0x00,0x00,0x00,

    0x00,0x00,0x00,0x7F,0x7F,0x20,0x20,0x20,0x20,0x20,0x7F,0x7F,0x00,0x00,0x00,0x00}, //日!

    {0x00,0xFC,0xFC,0x84,0x84,0xFE,0xFE,0x14,0x90,0x10,0x10,0xFF,0xFF,0x10,0x18,0x00,

    0x00,0x3F,0x1F,0x10,0x10,0x3F,0x3F,0x00,0x00,0x23,0x60,0xFF,0x7F,0x00,0x00,0x00}, //时!

    {0x80,0x40,0x70,0xCF,0xC8,0x48,0x00,0xF8,0xF0,0x10,0xFF,0xFF,0x10,0xF8,0xF0,0x10,

    0x00,0x02,0x22,0x7F,0x3F,0x12,0x08,0x07,0x03,0x02,0xFF,0xFF,0x02,0x07,0x07,0x00}, //钟!

    {0x00,0x20,0x18,0xCF,0xC7,0x44,0x44,0xFC,0xFC,0x44,0x44,0x64,0x46,0x04,0x00,0x00,

    0x04,0x04,0x04,0x07,0x07,0x04,0x04,0xFF,0xFF,0x04,0x04,0x04,0x04,0x06,0x04,0x00}, //

    {0x00,0x00,0x00,0x00,0xFF,0xFE,0x22,0x22,0x22,0x22,0x22,0xFF,0xFE,0x04,0x00,0x00,

    0x00,0x80,0x40,0x70,0x1F,0x07,0x02,0x02,0x02,0x42,0x42,0xFF,0x7F,0x00,0x00,0x00}, //

    {0x00,0xC0,0x60,0x38,0x9E,0x8E,0x80,0x80,0x83,0xCE,0x9C,0xB0,0xE0,0xC0,0xC0,0x80,

    0x01,0x80,0x40,0x60,0x38,0x1F,0x07,0x40,0x80,0x7F,0x3F,0x00,0x00,0x01,0x00,0x00}, //

    {0x00,0x00,0x00,0x80,0xE0,0x00,0xFE,0xFE,0x02,0x20,0x40,0x80,0x00,0x00,0x00,0x00,

    0x00,0x08,0x06,0x03,0x10,0x30,0x7F,0x7F,0x00,0x00,0x00,0x01,0x03,0x0E,0x00,0x00}, //

    {0x00,0x00,0xFE,0xFE,0x42,0x42,0x42,0x42,0xFE,0xFE,0x42,0x42,0xC3,0xE2,0x40,0x00,

    0x40,0x30,0x0F,0x83,0x40,0x30,0x18,0x0E,0x07,0x21,0x40,0xC0,0x7F,0x3F,0x00,0x00}}; //

    //============================================================================== //

    //========== miniLcd.h ============

    //头文件包括引脚操作宏定义以及液晶有关的函数说明,以供主程序调用

    //

    #include <avr/io.h>

    #include <avr/pgmspace.h>

    #include <util/delay.h>

#define CS_H PORTD|=(1<<PD0) //ena PD0高低控制 !片选线

    #define CS_L PORTD&=~(1<<PD0)

#define RST_H PORTD|=(1<<PD1) //rst PO1高低控制!复位线

    #define RST_L PORTD&=~(1<<PD1)

#define AO_H PORTD|=(1<<PD2) //com/data PD2高低控制!命令-数据线

    #define AO_L PORTD&=~(1<<PD2)

    #define SCL_H PORTD|=(1<<PD3) //clock PD3高低控制!时钟线 #define SCL_L PORTD&=~(1<<PD3)

    #define SI_H PORTD|=(1<<PD4) //seriel data PD4高低控制!数据线 #define SI_L PORTD&=~(1<<PD4)

    #define uchar unsigned char #define uint unsigned int

//以下都是这个LCD的有关驱动函数申明

    void Lcd_ini();

    void LcdWriByte(uchar n) ; void LcdWriCommand(uchar comm); void LcdWriData(uchar dat); void LcdSetxy(uchar x,uchar y); void LcdCls(char val);

    void LcdReset(void) ;

    void LcdOff(void);

void LcdShow88(uchar x,uchar y,const char *p);

    void LcdShow1616(uchar x,uchar y,const char *p) ;

    void LcdShow1216(uchar x,uchar y,const char *p) ;

/////////////////////////////////////////////////////////////////////

    /////////////////////////// //====== miniLcd.c=========== #include"miniLcd.h"

void Lcd_ini() //lcd初始化

    {

     LcdWriCommand(0xaf); //显示开

     LcdWriCommand(0x40); //起始行0

     LcdWriCommand(0xa0); //正常方向!左-

     LcdWriCommand(0xa6); //正常显示;白背景

     LcdWriCommand(0xa4); //正常关全屏显示

     LcdWriCommand(0xa2); //1/9偏压

     LcdWriCommand(0xc8); //0行在上,正常由上往下显示

     LcdWriCommand(0x2f); //内部电源设置默认值

     LcdWriCommand(0x24); //分压比!对比度默认值

     LcdWriCommand(0x81); //亮度默认值

     LcdWriCommand(0x20); //VOLUME REGISTER SET默认值

    }

    ////////////////////////////

    void LcdWriByte(uchar nn) //lcd串写1字节从最高位开始 {

     int i;

     SCL_L;

     for(i=8;i>0;i--)

     {

     SCL_L;

     if(nn&0X80)

     SI_H;

     else

     SI_L;

     SCL_H;

     nn<<=1;

     }

}

    ////////////////////////////

    void LcdWriCommand(uchar comm) //lcd写命令 {

     CS_L;

     AO_L;

     LcdWriByte(comm);

     CS_H;

    }

    ////////////////////////////

    void LcdWriData(uchar data) //lcd写数据 {

     CS_L;

     AO_H;

     LcdWriByte(data);

     CS_H;

    }

    //////////////////////////////

void LcdSetxy(uchar x,uchar y) //lcd设置显示坐标x:0-127;y:0-7

    {

     uchar tmp=0;

     y&=0x0f; //y0xb0组合

     y|=0xb0;

     tmp=x; //x组合成新的高4

     tmp>>=4;

     tmp|=0x10;

     x&=0x0f; //x取低4

     LcdWriCommand(y);

     LcdWriCommand(tmp); //x 4

     LcdWriCommand(x); //x 4

    }

    //////////////////////////////

    void Lcd