×
嵌入式 > 嵌入式开发 > 详情

单片机12232 C语言的驱动程序

发布时间:2020-08-27 发布时间:
|
/****************点阵12232函数调用库**********************/

//////////////////////////////////////////////////////////
#include
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int

#define frist_page 0xb8 //页地址设置(0~3)
#define frist_row 0xc0 //扫描行 (0~31)
#define frist_line 0x00 //列地址设置(0~61)


bit R=1,W=0,C=0,D=1;
/*******指令集***********************
do_12232(W,C,1,1,0XAE); //开关屏 +1开
do_12232(W,C,1,1,0XC0); //起始行 0~31
do_12232(W,C,1,1,0XB8); //页地址 0~4
do_12232(W,C,1,1,0X00); //列地址 0~80
do_12232(W,C,1,1,0XB1); //设置方向 正向 B0 为反向
do_12232(W,C,1,1,0XA4); //驱动模式 正常 +1静态
do_12232(W,C,1,1,0XA8); //duty设置 1/16 +1 1/32duty
do_12232(W,C,1,1,0XE0); //R-chang-W
do_12232(W,C,1,1,0XAE); //end
do_12232(W,C,1,1,0XE2); //reset
*////////////////////////////////////////////
void delayus(uint us)
{
uint uscnt;
uscnt=us>>3;
while(--uscnt);
}
void delayms(uint ms) // ms数量级 是实际时间的0.83倍
{
while(--ms)
{
delayus(250);
delayus(250);
delayus(250);
delayus(250);
}
}

void do_12232(bit RW,bit DC,bit chceE1,bit chceE2,uchar date)
{
a0=DC;
rw=RW;
P0=date;
if(chceE1){e1=1;e1=0;}
if(chceE2){e2=1;e2=0;}
}

void init_lcd (void)
{
rst=1;
do_12232(W,C,1,1,0xe2); //软件复位
do_12232(W,C,1,1,0xa4); //动态驱动
do_12232(W,C,1,1,0xae); //显示关闭
do_12232(W,C,1,1,0xa9); //刷新时钟设置1/32
do_12232(W,C,1,1,0xa0); //clockwise
do_12232(W,C,1,1,0xee); //写模式
do_12232(W,C,1,1,0xaf); //显示打开
}
/*///////清屏///////////////*/////////////////
void clear_screen()
{
uchar i,ii;
for(i=0;i<4;i++)
{
do_12232(W,C,1,1,frist_page+i);
do_12232(W,C,1,1,frist_row);
do_12232(W,C,1,1,frist_line);
for(ii=0;ii<61;ii++)
{
do_12232(W,D,1,1,0);
}
}
}
///////////任意位置写7*16的像素块////////////////////////
/*
每半屏的一页只能写8个字符空余5列
x 横向x=0第一行 x=2 第二行
y 列向y=0~16
*/
///////////////////////////////////////////////////////////
/*
加 do_12232(W,C,1,0,frist_row);是必要的的,每个像素都是在顶层
产生的,每写半屏的长度执行它可以通过滚屏达到指定的地点
*/
void write_one_char(uchar x,uchar y,uchar code *cha)
{
uchar i,ii;
for(ii=0;ii<2;ii++) //上下半屏分写
{
if(y/8) //左右半屏分写
{
do_12232(W,C,0,1,frist_page+x+ii); //值页
do_12232(W,C,0,1,frist_row+8*x); //扫描
do_12232(W,C,0,1,frist_line+7*(y-8));//值列
for(i=0;i<7;i++)
{
do_12232(W,D,0,1,cha[7*ii+i]);
}
do_12232(W,C,0,1,frist_row); //执行滚屏

}
else
{
do_12232(W,C,1,0,frist_page+x+ii);
do_12232(W,C,1,0,frist_row+8*x);
do_12232(W,C,1,0,frist_line+7*y+5);
for(i=0;i<7;i++)
{
do_12232(W,D,1,0,cha[7*ii+i]);
}
do_12232(W,C,1,0,frist_row);
}
}
}

///////////////////////////////////////////////////////////////////
/*
写任意像素15*16到指定位置
*/
void write_one_chinese(uchar x,uchar y,uchar code *cha)
{
uchar i,ii;
for(ii=0;ii<2;ii++) //上下半屏分写
{
if(y/4) //左右半屏分写
{
do_12232(W,C,0,1,frist_page+x+ii); //值页
do_12232(W,C,0,1,frist_row+8*x); //扫描
do_12232(W,C,0,1,frist_line+15*(y-4));//值列 ?
for(i=0;i<15;i++)
{
do_12232(W,D,0,1,cha[15*ii+i]);
}
do_12232(W,C,0,1,frist_row); //执行滚屏

}
else
{
do_12232(W,C,1,0,frist_page+x+ii);
do_12232(W,C,1,0,frist_row+8*x);
do_12232(W,C,1,0,frist_line+15*y);
for(i=0;i<15;i++)
{
do_12232(W,D,1,0,cha[15*ii+i]);
}
do_12232(W,C,1,0,frist_row);
}
}
}
//////////////////////////////////////////////////////////////////
/************任意位置写字符串************************************/
void write_chars(uchar x,uchar y,uchar code *cha,uchar quantity)
{
uchar i;
for(i=0;i{
write_one_char(x,y+i,cha+14*i);
}
}
/***********任意位置写汉字串************************************/
void write_characters(uchar x,uchar y,uchar code *cha,uchar quantity)
{
uchar i;
for(i=0;i{
write_one_chinese(x,y+i,cha+30*i);
}
}
/***********整屏122*32画一幅画************************************/
/*
如果数据是从上至下有序下沉则每次不必置
do_12232(W,C,0,1,frist_row);
*/
void display_piture(uchar *cha)
{
uchar i,ii;
for(i=0;i<4;i++)
{
do_12232(W,C,1,1,frist_page+i);
do_12232(W,C,1,1,frist_row);
do_12232(W,C,1,1,frist_line);
for(ii=0;ii<122;ii++)
{
if(ii<61){do_12232(W,D,1,0,cha[122*i+ii]);}
else{do_12232(W,D,0,1,cha[122*i+ii]);}
}
}
}
////////////////////////////////////////////////////////////////////
void main()
{
init_lcd();
clear_screen();
write_chars(0,3,num,8);
write_chars(2,3,num,8);
while(1)
{
clear_screen();
(0,0,num,10);
delayms(5000);

clear_screen();
write_characters(0,0,pray,8);
write_characters(2,1,write_me,5);
delayms(5000);

clear_screen();
display_piture(tup);
delayms(5000);
}
}

dewei.h 文件 定义与单片机的接口

//DATA P0;
sbit rst=P2^4;//复位
sbit e1 =P2^1;// 使能
sbit e2 =P2^2;
sbit rw =P2^3;
sbit a0 =P2^0;//数据指令

table.h 文件 注入flash(code)的数据表

//字模"0123456789"
unsigned char code num[]={
0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,/*"0"*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,/*"1"*/
0x00,0x70,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x2C,0x22,0x21,0x30,0x00,/*"2"*/
0x00,0x30,0x08,0x88,0x88,0x70,0x00,0x00,0x18,0x20,0x20,0x31,0x1E,0x00,/*"3"*/
0x00,0x80,0x40,0x20,0xF8,0x00,0x00,0x06,0x05,0x04,0x24,0x3F,0x24,0x04,/*"4"*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x00,0x00,0x19,0x21,0x20,0x31,0x1F,0x00,/*"5"*/
0xE0,0x10,0x88,0x88,0x88,0x18,0x00,0x0F,0x11,0x20,0x20,0x31,0x1F,0x00,/*"6"*/
0x00,0x38,0x08,0x08,0xE8,0x18,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,/*"7"*/
0x70,0x98,0x88,0x08,0x98,0x70,0x00,0x1E,0x21,0x21,0x21,0x31,0x1E,0x00,/*"8"*/
0xF0,0x08,0x08,0x08,0x18,0xE0,0x00,0x31,0x22,0x22,0x32,0x19,0x07,0x00,/*"9"*/

unsigned char code tup[]={
/*-- 一幅图像: --*/
/*-- 宽度x高度=122x32 --*/
0x00,0x00,0x00,0x70,0xF8,0xF8,0xFC,0xFC,0xFE,0xFE,0xFE,0xFE,0xFC,0xFC,0xF0,0xE0,
0xC0,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,0x80,0x40,0x20,0x10,0x48,0xD4,0xB4,0x62,0xC2,0x82,0x03,0x02,0x02,
0x02,0x84,0xC4,0xE0,0xA0,0xE0,0x60,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xB0,0xF8,0xF0,0xF0,0xF8,0xFC,0x60,0x60,0x30,
0x18,0x00,0x00,0x00,0x80,0xC0,0xE0,0xE0,0xF0,0xF0,0xF0,0xD8,0x58,0x58,0x58,0x58,
0x58,0xD8,0xD8,0x98,0xB0,0x30,0x70,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x07,
0x07,0x07,0x02,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFC,0xFC,0xFC,0xFC,
0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xF8,0xF0,0xC0,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x01,0x00,0x04,
0x0D,0x1B,0x36,0x6D,0xDB,0xF6,0xED,0xFB,0xFE,0xFE,0xFF,0x7F,0x1F,0x07,0x01,0x00,
0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0xFC,0xFE,0xFE,
0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFC,0xE0,0xC0,0xC0,0xF8,0xFE,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x3E,0xF8,0x01,0x37,
0x0C,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x60,0xFF,0xC7,0x03,0x03,0x03,0x03,0xE1,
0xFF,0x3F,0x0F,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x0F,0x3F,0x7F,0xFF,0xEF,
0xBF,0x7F,0xFF,0xC7,0x07,0x1F,0xFE,0xF8,0xB0,0x60,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x04,0x08,0x10,0x20,0x40,0x40,0x80,0x83,
0xFF,0xFF,0xFF,0xFF,0x83,0x40,0x40,0x20,0x10,0x08,0x04,0x03,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x03,0x07,0x0F,0x1F,0x3F,0x3F,0x7F,0xFF,
0xFF,0x7F,0x7F,0xFF,0xFF,0xFF,0xFF,0xDF,0x3F,0x3F,0x0F,0x61,0x3F,0x1F,0x2F,0x3F,
0x1F,0x0F,0x00,0x0F,0x07,0x03,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x1E,0x07,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x40,0x60,0x70,0x3C,0x1F,0x07,0x03,0x01,0x01,0x00,0x00,
0x01,0x07,0x07,0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0xEC,0x00,
0x7C,0x44,0x7C,0x00,0x7C,0x40,0x40,0x00,0x7C,0x44,0x38,0x00,0x7C,0x14,0x1C,0x00,
0x7C,0x40,0x40,0x00,0x78,0x24,0x78,0x00,0x7C,0x18,0x18,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x20,0x20,0x20,0x10,0x04,0x07,0x00,0x01,0x00,0x00,0x00,0x01,
0x05,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
unsigned char code pray[]=
{
/*------------------------------------------------------------------------------
; 源文件 / 文字 : 祝
; 宽×高(像素): 15×16
------------------------------------------------------------------------------*/
0x08,0x88,0xC9,0xEF,0xFE,0x98,0x7E,0x7E,0xC2,0xC2,0xC2,0xC2,0x7E,0x7E,0x00,
0x01,0x01,0x3F,0x3F,0x20,0x21,0x31,0x1c,0x0F,0x03,0x3F,0x3F,0x20,0x38,0x38,
/*------------------------------------------------------------------------------
; 源文件 / 文字 : 福
; 宽×高(像素): 15×16
------------------------------------------------------------------------------*/
//宽的像素数,高的像素数,宽的字节数,参数设置可选
0x08,0x08,0x88,0xEE,0xFE,0x98,0x80,0xBA,0xBA,0xAA,0xAA,0xBA,0xBA,0x82,0x00,
0x02,0x03,0x01,0x3F,0x3F,0x01,0x3F,0x3F,0x12,0x1F,0x1F,0x12,0x3F,0x3F,0x00,
/*------------------------------------------------------------------------------
; 源文件 / 文字 : 我
; 宽×高(像素): 15×16
------------------------------------------------------------------------------*/
0x00,0x14,0x14,0x96,0xFF,0xFF,0x10,0x10,0xFF,0xFF,0x10,0xDC,0xDC,0x10,0x00,
0x04,0x06,0x13,0x33,0x3F,0x1F,0x08,0x08,0x0F,0x07,0x0F,0x19,0x30,0x3c,0x3c,
/*------------------------------------------------------------------------------
; 源文件 / 文字 : 家
; 宽×高(像素): 15×16
------------------------------------------------------------------------------*/
0x00,0x8C,0x8C,0xD4,0x54,0xF4,0xF5,0xD7,0x96,0x94,0xD4,0x74,0x2C,0x0C,0x00,
0x00,0x00,0x12,0x12,0x1B,0x0D,0x26,0x23,0x3F,0x3F,0x03,0x06,0x1c,0x18,0x08,
/*------------------------------------------------------------------------------
; 源文件 / 文字 : 暑
; 宽×高(像素): 15×16
------------------------------------------------------------------------------*/
0x80,0x80,0x80,0xBE,0xBE,0xAA,0xEA,0xEA,0xAA,0xEA,0xFE,0xBE,0x80,0x80,0x80,
0x04,0x04,0x06,0x02,0x3F,0x3F,0x2B,0x2B,0x2a,0x2a,0x3e,0x3e,0x00,0x00,0x00,
/*------------------------------------------------------------------------------
; 源文件 / 文字 : 假
; 宽×高(像素): 15×16
------------------------------------------------------------------------------*/
0x20,0x30,0xFC,0xFF,0x03,0xFE,0xFE,0x92,0xBE,0xBE,0x92,0x92,0xBE,0xBE,0x00,
0x00,0x00,0x3F,0x3F,0x00,0x3F,0x3F,0x22,0x22,0x37,0x1F,0x1c,0x37,0x23,0x20,
/*------------------------------------------------------------------------------
; 源文件 / 文字 : 快
; 宽×高(像素): 15×16
------------------------------------------------------------------------------*/
0x60,0x30,0xFF,0xFF,0xB0,0xE8,0x88,0x88,0xFF,0xFF,0x88,0xF8,0xF8,0x80,0x80,
0x00,0x00,0x3F,0x3F,0x20,0x30,0x18,0x0e,0x07,0x07,0x0e,0x18,0x30,0x30,0x20,
/*------------------------------------------------------------------------------
; 源文件 / 文字 : 乐
; 宽×高(像素): 15×16
------------------------------------------------------------------------------*/
0x00,0x00,0x70,0x7E,0x4E,0x42,0x42,0xFA,0xFB,0x43,0x40,0x40,0x40,0x40,0x00,
0x00,0x10,0x18,0x0c,0x07,0x13,0x30,0x3F,0x1F,0x01,0x03,0x06,0x1e,0x18,0x00
};

unsigned char code write_me[]=
{
/*------------------------------------------------------------------------------
; 源文件 / 文字 : 孙
; 宽×高(像素): 15×16
------------------------------------------------------------------------------*/
0x06,0x06,0x86,0xF6,0xFE,0xEE,0x26,0x80,0x80,0xFE,0xFE,0xE0,0xC0,0x00,0x00,
0x0c,0x26,0x63,0xFF,0xFF,0x18,0x0e,0x17,0x71,0xFF,0xFF,0x00,0x01,0x07,0x0e,
/*------------------------------------------------------------------------------
; 源文件 / 文字 : 孝
; 宽×高(像素): 15×16
------------------------------------------------------------------------------*/
0x20,0x20,0xA4,0xA4,0xA4,0xA4,0xFF,0xFF,0xE4,0xB4,0xB4,0x24,0x20,0x20,0x20,
0x08,0x08,0x08,0x0c,0x0e,0x4B,0xC9,0xFe,0xFF,0x09,0x08,0x08,0x08,0x08,0x08,
/*------------------------------------------------------------------------------
; 源文件 / 文字 : 亮
; 宽×高(像素): 15×16
------------------------------------------------------------------------------*/
0x00,0x04,0x04,0x74,0x74,0x54,0x57,0x57,0x54,0x54,0x74,0x74,0x04,0x04,0x00,
0x04,0x07,0x83,0xC1,0x7D,0x3D,0x05,0x05,0xFD,0xFD,0x81,0x85,0x87,0xE7,0xE0,
/*------------------------------------------------------------------------------
; 源文件 / 文字 : 研
; 宽×高(像素): 15×16
------------------------------------------------------------------------------*/
0x06,0xC6,0xFE,0xFE,0xC6,0xC6,0x00,0xC6,0xFE,0xFE,0xC6,0xFE,0xFE,0xC6,0xC6,
0x01,0x1F,0x1F,0x10,0x1F,0x1F,0x20,0x30,0x1F,0x0F,0x00,0x7F,0x7F,0x00,0x00,
/*------------------------------------------------------------------------------
; 源文件 / 文字 : 制
; 宽×高(像素): 15×16
------------------------------------------------------------------------------*/
0x30,0x5E,0x5E,0x48,0xFF,0xFF,0x48,0x48,0x48,0x00,0xFC,0xFC,0x00,0xFF,0xFF,
0x00,0x3F,0x3F,0x01,0xFF,0xFF,0x21,0x7F,0x7F,0x00,0x0F,0x2F,0x61,0xFF,0xFe
};



『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
基于嵌入式系统的CAN总线网络通信流程设计