⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcm12864.h

📁 我写的L297步进电机的驱动
💻 H
字号:
//ICC-AVR application builder
// Target : ATMEGA16
// Crystal: 1Mhz
// YM12864R (ST7920) 驱动
// 地址:    第一行:     0x80-0x87
//          第二行:     0x90-0x97
//          第三行:     0x88-0x8f
//          第四行:     0x98-0x9f
//   cacliu   2007.10.6
//程序调用指令:
//Send_CMD();
//Send_DATA();
//LCM_init();
//LCD_CLR();
//DisHZ(unsigned int LCD_COMMAND,unsigned int x, unsigned char *HZS);
//DisBMP(const unsigned char *img);
//****************************************


#define     uint       unsigned int

#define        Set_CLK    PORTB |= (1 <<4)    //PORTB|=0x10
#define        Clr_CLK    PORTB &= ~(1 <<4)   //PORTB&=~0x10
#define        Set_DAT    PORTB |= (1 << 6)   //PORTB|=0x40
#define        Clr_DAT    PORTB &= ~(1 << 6)  //PORTB&=~0x40
#define        Set_CS     PORTB |= (1 << 5)   //PORTB|=0x20
#define        Clr_CS     PORTB &= ~(1 << 5)  //PORTB&=~0x20
#define        DATOUT         DDRB|=0x80  
#define        DATIN          DDRB&=~0x80
#define        DAT_High       PINB&0x80
//****************************************
void    delayus(char    us)
{
    for (;us!=0;us--)
        {WDR();}
    }
//****************************************
void    delayms(uint ms)
{
    uint    i;

    for (;ms!=0;ms--)
        {for (i=461;i!=0;i--)
            {WDR();WDR();}
        }

}

//---------------------------------------------------------
void    data_trans(char data)
{
    char i;

    for (i=8;i!=0;i--)
        {if (data&0x80)Set_DAT;
            else Clr_DAT;
        Clr_CLK;
        data<<=1;
        Set_CLK;
        }
}
//---------------------------------------------------------
void   Send_CMD(char   com)
{
    char    temp;

Set_CS;
    temp=0xF8;
    data_trans(temp);
    temp=com&0xF0;
    data_trans(temp);
    temp=com&0x0F;temp<<=4;
    data_trans(temp);
Clr_CS;
delayus(70);
}
//---------------------------------------
void    LCD_Set_DDRAM(char addr)
{Send_CMD(addr);}

void    LCD_HOME(void)
{Send_CMD(0x02);}

void    LCD_CLR(void)
{Send_CMD(0x01);delayms(2);}
//----------------------------------------------------------
void    Send_DATA(char data)
{
    char    temp;
Set_CS;
    temp=0xFA;
    data_trans(temp);
    temp=data&0xF0;
    data_trans(temp);
    temp=data&0x0F;temp<<=4;
    data_trans(temp);
Clr_CS;
delayus(40);
}

//--------------设置XY-----------------//

void LCD_set_xy( unsigned char x, unsigned char y )  //写地址函数
{
    unsigned char address;
    if (y == 0) address = 0x80 + x;
    else  if(y == 1) address = 0x90 + x;
		  else if(y == 2) address = 0x88 + x;
		  	   else address = 0x98 + x;	
    Send_CMD(address);
}
//************************************************************
//----------------------------------------
//************************************************************
void    LCM_init(void)
{
delayms(50);
Send_CMD(0x20);//Function Set命令必须发送两次
Send_CMD(0x20);
Send_CMD(0x0C);//整体显示ON,游标OFF,
LCD_CLR();        //CLR
Send_CMD(0x06);//AC++
}
//************************************************************
//自定义全角字符,最多4个,保存在CGRAM中
char    const    font_wd[]=    //℃
{0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x0A,0xF0,0x05,0x88,0x03,0x00,0x02,0x00,
0x02,0x00,0x03,0x00,0x01,0x88,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

char    const    font_bfh[]= //%
{0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x02,0x4C,0x02,0x58,0x01,0xB0,0x00,0x60,
0x00,0xD8,0x01,0xA4,0x03,0x24,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};


//-----------显示汉字串-----------------//
void DisHZ(unsigned int LCD_COMMAND,unsigned int x, unsigned char *HZS)
{
unsigned char i;
Send_CMD(LCD_COMMAND);
for (i=0;i<x;i++)
Send_DATA(HZS[i]);
}

//-----------显示汉字串XY-----------------//
void DisHZXY(unsigned int x,unsigned int y,unsigned int z, unsigned char *HZS)
{
unsigned char i;
LCD_set_xy(x,y);
for (i=0;i<z;i++)
Send_DATA(HZS[i]);
}

//-----------显示一个汉字--------------//
void DisOneHZ(unsigned int LCD_COMMAND, unsigned char Data)
{
Send_CMD(LCD_COMMAND);
Send_DATA(Data);
}

/*-------------显示图片---------------*/
void DisBMP(const unsigned char *img)
{  
    unsigned int j=0;
    unsigned char x,y,i;
    for(i=0;i<9;i+=8)
    for(y=0;y<32;y++)
    for(x=0;x<8;x++)
         {  Send_CMD(0x36);
            Send_CMD(y+0x80);   
            Send_CMD(x+0x80+i);
            Send_CMD(0x30);
            Send_DATA(img[j++]);
            Send_DATA(img[j++]);
         }             
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -