ST7920控制显示程序

发布者:RadiantEyes最新更新时间:2016-10-26 来源: eefocus关键字:ST7920控制  显示程序 手机看文章 扫描二维码
随时随地手机看文章
/****************************************************************************************

           LCM(DM12864M-带字库,ST7920控制芯片)mega8控制显示程序   
                                                  
             程序功能:该程序是用AVR来控制对DM12864M
              读写信号等的操作.
             硬件连接:采用串行方式显示,分配PD.3=SID,PD.2=SCK,PB.1=LCD_ON
              三个I/O口分别作为LCM数据,时钟信号,背光开关
        的控制。
        CS和/RESET直接接VCC;PSB直接接GND 

****************************************************************************************/

#include
#include
#include   
#define LCDDDR        DDRD
#define LCDDDR_IN     LCDDDR&=~BIT(PD3);
#define LCDDDR_OUT    LCDDDR|=BIT(PD0)|BIT(PD3)|BIT(PD2)|BIT(PD1);
/*===============================================================*/
#define LCDCTL      PORTD   
#define SID_ON      LCDCTL |= BIT(PD3)  //数据                            
#define SID_OFF     LCDCTL &= ~BIT(PD3)  
#define SCK_ON      LCDCTL |= BIT(PD2)  //时钟                          
#define SCK_OFF     LCDCTL &= ~BIT(PD2) 
#define LCD_ON      LCDCTL |= BIT(PB1)  //开启背光
#define LCD_OFF     LCDCTL &= ~BIT(PB1)  
//#define uchar unsigned char
/***********************函数体部分*********************************/
unsigned char  AC_TABLE[]={
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
};
unsigned char  str2[]="欢迎光临AVRLCD!!";
unsigned char  str1[]="云母屏风烛影深,长河渐落晓星沉。嫦娥应悔偷灵药,碧海青天夜夜心。";
unsigned char  bmp1[];//先声明一下就可以把表放在函数后面啦,呵呵
//=========发送一个字节程序=========
void SendByte(unsigned char Dbyte)
{
    unsigned char i;
    for(i=0;i<8;i++)
  {
     if(Dbyte&0x80)SID_ON;
    else SID_OFF;
    SCK_ON;
    SCK_OFF;
    Dbyte=Dbyte<<1;
  }
}
//接收一个字节程序((0xf0&temp1)+(0x0f&temp2))
unsigned char ReceiveByte(void)  
{
    unsigned char i,temp1,temp2;
    temp1=temp2=0;
    for(i=0;i<8;i++)
    {
     LCDDDR_IN;
  temp1=temp1<<1;
        if ((PINC&0x02)==0)temp1++;  //与端口设置有关,主要修改端口时修改此位
     LCDDDR_OUT;
  SCK_ON;
    SCK_OFF;
   }
    for(i=0;i<8;i++)
    {
     LCDDDR_IN;
  temp2=temp2<<1;
        if ((PINC&0x02)==0)temp2++;  //与端口设置有关,主要修改端口时修改此位
  LCDDDR_OUT;
  SCK_ON;
    SCK_OFF;
    }
        return ((0xf0&temp1)+(0x0f&temp2));
}
//液晶忙检查CheckBusy
void CheckBusy( void )               
{
    do SendByte(0xfc);               //11111,RW(1),RS(0),0
    while(0x80&ReceiveByte());
}
//========写命令========
void WriteCommand( unsigned char Cbyte )
{
 CheckBusy();
    SendByte(0xf8);                //11111,RW(0),RS(0),0
    SendByte(0xf0&Cbyte);
    SendByte(0xf0&Cbyte<<4);
}
//========写数据========
void WriteData( unsigned char Dbyte )
{
    CheckBusy();
    SendByte(0xfa);             //11111,RW(0),RS(1),0
    SendByte(0xf0&Dbyte);
    SendByte(0xf0&Dbyte<<4);
}
//========读数据========
unsigned char ReadData( void )
{
    CheckBusy();
    SendByte(0xfe);             //11111,RW(1),RS(1),0
    return ReceiveByte();
}
//===延时程序 ,12M/ms==
void Delay(unsigned int MS)
{
    unsigned char us,usn;
    while(MS!=0)               //for 12M
    { 
     usn = 2;
     while(usn!=0)
        {
            us=0xf5;
            while (us!=0){us--;};
            usn--;
        }
        MS--;
    }
}
//=====液晶初始化======
void LcmInit( void )          
{
    WriteCommand(0x30); //基本指令,选择8位CPU控制方式,关图显
    WriteCommand(0x03); //复位地址计数器
    WriteCommand(0x0C); //开整体显示
    WriteCommand(0x01); //清除屏显的数据
    WriteCommand(0x06); //设置地址计数器递增
}
//=======清文字========
void LcmClearTXT( void )     
{
    LcmInit();
}
//=======清图片========
void LcmClearBMP( void )    
{
    unsigned char i,j;
    WriteCommand(0x34);    //关图显
    for(i=0;i<32;i++)
    {
        WriteCommand(0x80|i); //写入列地址
        WriteCommand(0x80);   //写入行地址
        for(j=0;j<32;j++)
        WriteData(0);
    }
 //WriteCommand(0x36);//开图显
}
//==写入一段文字,写完一屏,清屏,从头在写新的一屏=======
void PutStr(unsigned char row,unsigned char col,unsigned char *puts)
{
    WriteCommand(0x30);     //基本指令,选择8位CPU控制方式,关图显
    WriteCommand(AC_TABLE[8*row+col]);
    while(*puts != '\0')
    {
        if(col==8)
        {
            col=0;
            row++;
        }
        if(row==4) row=0;
        WriteCommand(AC_TABLE[8*row+col]);
        WriteData(*puts);  //一个汉字的ASC码是一个16位的,所以要写入两个字节
        puts++;
        WriteData(*puts);
        puts++;
        col++;
 }
}
//========写入一屏图片128*64=======
void PutBMP(unsigned char *puts)
{
    unsigned char x,y,i,j,k;
 x=0x80;
 WriteCommand(0x34);     //关图显
    for(k=0;k<2;k++)
 { 
     y=0x80;
  for(j=0;j<32;j++)
  {
      WriteCommand(y); //写入列地址
            WriteCommand(x);   //写入行地址
            for(i=0;i<16;i++)
   {
    WriteData(*(puts++));   
   }
   y++;
  }
  x=0x88;
 }
 WriteCommand(0x36);   //开图显
}

//===========主函数===========
void main( void )
{
    LcmInit();
    Delay(10);
    PORTB=0xff;
    LCD_ON;
 while(1)
    {
  PutStr(1,0,str2);
        Delay(10000);
  
  LcmClearTXT();
  Delay(10); 
  
  PutStr(0,0,str1);
        Delay(10000);
  
  LcmClearTXT();
  Delay(10); 
  
  PutBMP(bmp1);
        Delay(10000);
        
  LcmClearBMP();
          
    }
}
//==============================================================================
unsigned char  bmp1[]={/*生日蛋糕*/
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,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x01,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x80,0x07,0x38,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x04,0x00,0x00,0x40,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x10,0x40,0x00,0x00,0xC0,0x00,0x01,0xC0,
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x80,0x10,0x40,0x00,0x03,0x98,0x00,0x01,0xC0,
0x00,0x00,0x12,0x00,0x00,0x00,0x40,0x80,0x11,0xF0,0x00,0x01,0x08,0x00,0x03,0x80,
0x00,0x00,0x13,0x00,0x00,0x30,0x40,0x80,0x10,0x50,0x06,0x01,0x08,0x00,0x03,0x80,
0x00,0x00,0x11,0x00,0x00,0x48,0x40,0x80,0x10,0x50,0x19,0x83,0xFF,0x80,0x03,0x00,
0x00,0x00,0x17,0x80,0x01,0xCE,0x40,0x80,0x5B,0xFC,0x06,0x00,0x08,0x00,0x07,0x00,
0x00,0x00,0x1F,0xE0,0x00,0x30,0x7F,0x80,0xD4,0x80,0x00,0x00,0x08,0x00,0x06,0x00,
0x00,0x00,0x11,0x00,0x00,0x30,0x40,0x80,0x91,0xA0,0x00,0x00,0xC9,0x00,0x00,0x00,
0x00,0x00,0x31,0x00,0x00,0x00,0x40,0x80,0x11,0x30,0x00,0x01,0x89,0x80,0x04,0x00,
0x00,0x00,0x67,0xC0,0x00,0x00,0x40,0x80,0x13,0x18,0x00,0x03,0x08,0xC0,0x0E,0x00,
0x00,0x00,0xC1,0x00,0x00,0x00,0x40,0x80,0x16,0x0C,0x00,0x02,0x08,0x60,0x0E,0x00,
0x00,0x00,0x01,0x00,0x00,0x00,0x7F,0x80,0x14,0x04,0x00,0x00,0x78,0x00,0x04,0x00,
0x00,0x00,0x01,0x00,0x00,0x00,0x41,0x80,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0x00,0x0E,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1B,0x00,0x00,0x00,0x01,0xF0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1B,0x80,0x00,0x00,0x01,0x30,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x34,0xC0,0x03,0x00,0x07,0x5C,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x31,0xC0,0x03,0x80,0x06,0x18,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x39,0xC0,0x06,0xC0,0x02,0x98,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x0F,0x00,0x0C,0xC0,0x03,0xF0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x18,0x70,0x00,0x40,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1F,0xF8,0x2C,0x28,0x3D,0xF0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1F,0x86,0xCC,0x66,0xC3,0xF1,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x06,0x3F,0x81,0x06,0xC1,0x81,0xFE,0xE0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x19,0xDF,0xFF,0xFF,0xFF,0xFF,0xF7,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x61,0xDF,0x80,0x07,0xC0,0x01,0xFC,0x0C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xF1,0x1F,0x80,0x07,0xC0,0x01,0xF0,0x1F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x1C,0x0F,0x00,0x07,0xC0,0x00,0xE0,0x71,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x1E,0x00,0x00,0x03,0x80,0x00,0x00,0xC1,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xE3,0x1E,0x00,0x00,0x00,0x00,0x71,0x0F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x30,0xE3,0x38,0x38,0x38,0x39,0x8E,0x19,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x0F,0xC3,0xC6,0xC6,0xC6,0xC7,0x07,0xF1,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x00,0x3F,0x01,0x81,0x01,0x01,0xF8,0x01,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xC0,0x00,0xFF,0xFF,0xFF,0xFE,0x00,0x07,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x39,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x87,0xC0,0x00,0x00,0x00,0x00,0x07,0xC1,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x00,0x3F,0xC0,0x00,0x00,0x07,0xF8,0x09,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xF0,0x00,0x7F,0xFF,0xFF,0xF8,0x04,0x2F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x1E,0x22,0x00,0x04,0x10,0x04,0x40,0xF1,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x1F,0x03,0xC0,0x20,0x40,0x84,0x80,0x07,0x01,0xF0,0x00,0x00,0x00,
0x00,0x00,0x00,0x23,0x00,0x3F,0xF2,0x08,0x00,0x47,0xFC,0x01,0x88,0x00,0x00,0x00,
0x00,0x00,0x00,0xC1,0x00,0x00,0x1F,0xFF,0xFF,0xFC,0x00,0x01,0x06,0x00,0x00,0x00,
0x00,0x00,0x00,0xC0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x06,0x00,0x00,0x00,
0x00,0x00,0x00,0xC4,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x06,0x00,0x00,0x00,
0x00,0x00,0x00,0xC0,0x01,0xF0,0x00,0x00,0x00,0x00,0x0F,0x00,0x42,0x00,0x00,0x00,
0x00,0x00,0x00,0x30,0x60,0x1F,0xC0,0x00,0x00,0x07,0xF0,0x1C,0x1C,0x00,0x00,0x00,
0x00,0x00,0x00,0x1F,0xC0,0x00,0x3F,0xFF,0xFF,0xF8,0x00,0x07,0xF0,0x00,0x00,0x00,/*
0x00,0x00,0x00,0x00,0xC2,0x00,0x00,0x00,0x00,0x00,0x00,0x86,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xC0,0x18,0x00,0x00,0x00,0x00,0x30,0x06,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x30,0x78,0x00,0xC1,0x06,0x08,0x38,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x1F,0xCC,0x00,0xE0,0x06,0x00,0x37,0xE0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x06,0x13,0x38,0x59,0x82,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x03,0xFE,0x0F,0xF0,0xFF,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00*/
};

关键字:ST7920控制  显示程序 引用地址:ST7920控制显示程序

上一篇:AT24CXX的mega8控制程序
下一篇:AVR的模拟比较器功能实验

推荐阅读最新更新时间:2024-03-16 15:17

基于STC15F2K60S2的内部AD转换程序(1602显示
第一次学习也是第一次使用STC15F2K60S2进行AD转换,感觉比之前用89c52加AD芯片好用多了,虽然中间走了很多弯路,但是最终还是成功了,分享给那些和我一样刚学习单片机的童鞋们,希望能够帮到你们! 单片机源程序如下: #include STC15F2K60S2.h #include ADC.h unsigned int ADC_DATE1,ADC_DATE2; bit flag; void delay(unsigned int sec) //延时函数 { while(sec--); } void Init_ADC() //ADC初始化 { P1ASF=0X80;
[单片机]
液晶显示控制ST7920的接口方式研究与编程
1 引言   ST7920是台湾矽创电子公司生产的中文图形液晶控制器,可作为控制器和驱动器捉供32路com 输出和64路seg输出。与驱动器ST7921组成的模块最多可驱动256×32点阵液晶,主要用于显示汉字及图形,其内置了2 MB中文字型ROM(CGROM),共提供8192个中文字型(16×16点阵);16KB半宽字型ROM(HCGROM),共提供126个西文字型(16×8点阵);64×16位字符显示RAM(DDRAM最多16字符×4行,LCD显示范围16×2行);64×16位字符产生RAM(CGRAM);15×16位共240点的ICON RAM(ICONRAM)。此外,为了适应多种微处理器与单片机接口需求,该模块还可
[模拟电子]
51单片机驱动1602液晶显示器c程序
/* 程序效果:单片机控制液晶显示器1602显示字母数字,用户自行更改io 程序版权:http://www.51hei.com */ #include reg52.h //头文件 #define uchar unsigned char //宏定义 #define uint unsigned int uchar code table ="51HEI XING XING " ; //显示的字母 uchar code table1 ="51HEI MCU XUE YUAU" ; sbit lcdrs=P1^0; //寄存器选择引脚 sbit lcdwr=P1^1; //读写引脚 sbit lcde=P1^2; //片选引脚 void de
[单片机]
MSP430单片机控制lcd1602显示C程序
//MSP430写的1602液晶显示程序2011/8/26//硬件连接 //P4 数据口 P3.7---E P3.6---RW P3.5----RS #include msp430x14x.h #define uint unsigned int #define rw(x) P3OUT=(P3OUT&(~BIT6))|(x?BIT6:0); unsigned char table0 = hankouxueyuan ; unsigned char table1 = dianzisheji ; //**************延时**************************
[单片机]
基于AVR的4*4矩阵键盘扫描与LED显示程序
/************** 此程序在别人的基础上进行了一些修改,能应用到我的开发板中, 并与我自制的外接按键和LED灯配合使用,在此感谢原创者!!! 硬件:M16 作用:当按下按键时显示相对应的按键控制的LED灯 频率:8.000000MHZ 开发板:EasyAVR M16 v12 编译软件:ICCAVR6.31A 下载软件:AVRstudio4.14 编写人:伍建忠 编写日期:2011.10.14 修改日期: ************/ #include iom16v.h #include macros.h #define uchar unsigned char #define uint unsigned int uint
[单片机]
显示温度及时间(能调时闹时)的bascom-avr程序
$regfile = m16def.dat $crystal = 8000000 Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.2 , Rs = Portc.0 Config Lcd = 16 * 2 Config 1wire = Porta.0 '************************************************* Dim Id(8) As Byte Dim I As Byte Dim C(2) As Byte Dim T As Word
[单片机]
基于单片机的AD转换的数码管显示程序
*本例程采用AD0804芯片,硬件电路:cs片选端接P2.3,WR写数据端写P3.6,RD读数据端接P3.7,锁存端接P2.6脚,数码管位选端分别接P3.2 ,P3.3,P3.4,段选端接P1口*/ #include reg52.h //头文件 #define uint unsigned int//宏文件 #define uchar unsigned char//宏文件 uchar num;//变量 void delay3(uint z);//延时定义 void dissy();//延时函数定义 sbit ge=P3^2;//个位定义 sbit shi=P3^3;//十位定义 sbit bai=P3^4;//百位定义 sbit a
[单片机]
单片机P1口高四位做按键,低四位做输出显示程序
;有对应的C51程序 ;本程序主要是初步体现基于单片机的按键的设计, ;用P1口的低八位发光二极管显示,只是为了显示实验结果 ;2007-06-05 org 0000h ljmp start org 0060h start: mov a,#0f0h ;准备给P1口高四位置高,做输入 mov p1,a ;给P1口高四位置高 mov a,p1
[单片机]
小广播
添点儿料...
无论热点新闻、行业分析、技术干货……
设计资源 培训 开发板 精华推荐

最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

换一换 更多 相关热搜器件
随便看看
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved