|
MSP430+LCD12864 最全的程序,还请大家帮忙解释一下其中几个函数的意思。
[复制链接]
- //LCD_PSB=1
- #include
- typedef unsigned char uchar;
- typedef unsigned int uint;
- extern const unsigned shuzi_table[];
- #define LCD_DataIn P4DIR=0X00
- #define LCD_DataOut P4DIR=0XFF
- #define LCD2MCU_Data P4IN
- #define MCU2LCD_Data P4OUT
- #define LCD_CMDOut P3DIR|=0X07
- #define LCD_RS_H P3OUT|=0X01 //BIT0
- #define LCD_RS_L P3OUT&=0XFE //~BIT0
- #define LCD_RW_H P3OUT|=0X02 //BIT1
- #define LCD_RW_L P3OUT&=0XFD //~BIT1
- #define LCD_EN_H P3OUT|=0X04 //BIR2
- #define LCD_EN_L P3OUT&=0XFB //~BIT2
- /********************************
- 函数名:Delay_1ms
- 功能:延时月1ms的时间
- 参数:无
- 返回值:无
- *********************************/
- void Delay_1ms(void)
- {
- uchar i;
- for(i=150;i>0;i--) //数据需调测
- _NOP();
- }
- /*********************************
- 函数名:Delay_Nms
- 功能:延时N个1ms的时间
- 参数:n
- 返回值:无
- **********************************/
- void Delay_Nms(uint n)
- {
- uint n;
- for(i=n;i>0;i--)
- Delay_1ms();
- }
- /*********************************
- 函数名:Write_Cmd
- 功能:向液晶中写控制命令
- 参数:cmd--控制命令
- 返回值:无
- **********************************/
- void Write_Cmd(uchar cmd)
- {
- uchar lcdtemp=0;
- //判忙 查询方式
- LCD_RS_L;
- LCD_RW_H;
- LCD_DataIn;
- do
- {
- LCD_EN_H;
- _NOP();
- lcdtemp=LCD2MCU_Data;
- LCD_EN_L;
- }while(lcdtemp&0X80);
- LCD_DataOut;
- //LCD_RS_L;
- LCD_RW_L;
- MCU2LCD=cmd;
- LCD_EN_H;
- _NOP();
- LCD_EN_L;
- }
- /********************************
- function name:Write_Data
- funtion: write data to LCD
- parameter: dat
- return: none
- ********************************/
- void Write_Data(uchar dat)
- {
- uchar lcdtemp;
- //JUDGE
- LCD_RS_L;
- LCD_RW_H;
- LCD_DataIn;
- do
- {
- LCD_EN_H;
- lcdtemp=LCD2MCU_Data;
- _NOP();
- LCD_EN_L;
- }while(lcdtemp&=0X80);
- LCD_RS_H;
- LCD_RW_L;
- LCD_DataOut;
- MCU2LCD_Data=dat;
- LCD_EN_H;
- _NOP();
- LCD_EN_L;
- }
- /*********************************
- function name:Read_Data
- function:
- parameter:none
- return:the data from the port
- ***********************************/
- uchar Read_Data(void)
- {
- uchar dat;
- ucahr lcdtemp;
- LCD_RS_L;
- LCD_RW_H;
- LCD_DataIn;
- do
- {
- LCD_EN_H;
- lcdtemp=LCD2MCU_Data;
- _NOP();
- LCD_EN_L;
- }
- while(lcdtemp&0x80);
- LCD_RS_H;
- LCD_EN_H;
- dat=LCD2MCU_Data;
- _NOP();
- LCD_EN_L;
- return dat;
- }
- /*********************************
- funtion name:Ini_Lcd
- function:initial LCD
- parameter:none
- return:none
- **********************************/
- void Ini_Lcd(void)
- {
- LCD_CMDOut; //LCD控制端口设置为输出
- Delay_Nms(500);
- Write_Cmd(0X30);//8bit basic instrction
- Delay_1ms();
- Write_Cmd(0X02);//地址归位
- Delay_1ms();
- Write_Cmd(0X0C);//整体显示打开,游标关闭
- Delay_1ms();
- Write_Cmd(0x01);//clear
- Delay_1ms();
- Write_Cmd(0x06);//go right
- Delay_1ms();
- Write_Cmd(0x80);//DDRAM start from
- }
- /*******************************************
- function name:Disp_HZ
- function:display chinese charater
- parameter:addr---display from
- pt--pointer of the array of HZ
- num--number of HZ
- return:none
- ********************************************/
- void Disp_HZ(uchar addr,const uchar *pt,uchar num)
- {
- uchar i;
- Write_Cmd(addr);
- for(i=0;i<(num*2);i++)
- Write_Data(*(pt++));
- }
- /*******************************************
- function name:Clear_GDRAM
- function:clean the random data in GDRAM
- parameter:none
- return:none
- ********************************************/
- void Clear_GDRAM(void)
- {
- uchar i,j,k;
- Write_Cmd(0x34);
- i=0x80;
- for(j=0;j<32;j++)
- {
- Write_Cmd(i++);
- Write_Cmd(0x80);
- for(k=0;k<16;k++)
- {
- Write_Data(0x00);
- }
- }
- i=0x80;
- for(j=0;j<32;j++)
- {
- Write_Cmd(i++);
- Write_Cmd(0x88);
- for(k=0;k<16;k++)
- {
- Write_Data(0x00);
- }
- }
- Write_Cmd(0x30);
- }
- /*********************************************
- function name:Draw_PM
- function:draw pictures on LCD
- parameter:the pointer of the data of picture
- return:none
- **********************************************/
- void Draw_PM(const uchar *ptr)
- {
- uchar i,j,k;
- Write_Cmd(0x34);
- i=0x80;
- for(j=0;j<32;j++)
- {
- Write_Cmd(i++);
- Write_Cmd(0x80);
- for(j=0;j<32;j++)
- {
- Write_Data(*(ptr++));
- }
- }
- i=0x80;
- for(j=0;j<32;j++)
- {
- Write_Cmd(i++);
- Write_Cmd(0x88);
- for(k=0;k<16;k++)
- {
- Write_Data(*(ptr++));
- }
- }
- Write_Cmd(0x36);
- Write_Cmd(0x30);
- }
- /******************************************
- function name:Draw_UP
- function:up 128*32
- parameter:the pointer of data
- return:none
- ******************************************/
- void Draw_UP(const uchar *ptr)
- {
- uchar i,j,k;
-
- Write_Cmd(0x34);
- i=0x80;
- for(j=0;j<32;j++)
- {
- Write_Cmd(i++);
- Write_Cmd(0x80);
- for(k=0;k<16;k++)
- {
- Write_Data(*(ptr++));
- }
- }
- Write_Cmd(x036);//打开绘图开关
- Write_Cmd(0x30);
- }
- /******************************************
- fuction name:Draw_DN
- function:down 128*32
- patameter:the pointer of data
- return:none
- *******************************************/
- void Draw_DN(const uchar *ptr)
- {
- uchar i,j,k;
-
- i=0x80;
- Write_Cmd(0x34);
- for(j=0;j<32;j++)
- {
- Write_Cmd(i++);
- Write_Cmd(0x88);
- for(k=0;k<16;k++)
- {
- Write_Data(*(ptr++));
- }
- }
- Write_Cmd(0x36);
- WritE_Cmd(0x30);
- }
- /****************************************
- function name:Draw_Point
- fucntion:
- parameter:直角坐标,x水平坐标,y垂直坐标,color:1点亮0擦除。
- return:none
- *****************************************/
- void Draw_Point(const uchar x,const uchar y,const uchar color)
- {
- uchar row,collum,cbite;
- uchar tempH,tenpL;
- Write_Cmd(0x34);
- collum=x>>4;
- cbite=x&0x0f;
- if(y<32)
- row=y;
- else
- {
- row=y&0x1f;
- collum|=0x08;
- }
- Write_Cmd(0x80+row);
- Write_Cmd(0x80+collum);
- Read_Data();
- tempH=Read_Data();
- tempL=Read_Data();
- if(color)
- {
- if(cbite<8)
- tempH|=(0x80>>cbite);
- else
- tempL|=(0x80>>(cbite-8));
- }
- else
- {
- if(cbite<8)
- tempH&=~(0x80>>cbite);
- else
- tempL&=~(0x80>>(cbite-8));
- }
- Write_Cmd(0x80+row);
- Write_Cmd(0x80+collum);
- Wrtie_Data(tempH);
- Write_Data(tempL);
- Write_Cmd(0x36);
- Write_Cmd(0x30);
- }
- /*****************************************
- function name:Draw_RowLine
- fucnction:
- parameter:起点水平x0,终点水平x1,垂直y,color:1点亮0擦除
- return:none
- ******************************************/
- void Draw_RowLine(const uchar x0,const uchar x1,const uchar y,const uchar color)
- {
- uchar temp;
-
- if(x0>x1)
- {
- temp=x1;
- x1=x0;
- x0=temp;
- }
- do
- {
- Draw_Point(x0,y,color);
- x0++;
- }
- while(x0<=x1);
- }
- /******************************************************
- function name:Draw_CollumLine
- function:
- parameter:水平坐标x,起点垂直坐标y0,终点垂直坐标y1,color:1点亮2擦除
- return:none
- *******************************************************/
- void Draw_CollumLine(const uchar x.const uchar y0,const uchar y1,const uchar color)
- {
- uchar temp;
-
- if(y0>y1)
- {
- temp=y1;
- y1=y0;
- y0=temp;
- }
- do
- {
- Draw_point(x,y0,color);
- y0++;
- }
- while(y0<=y1);
- }
- /**********************************************
- function name:Draw_Line
- function:使用Bresenham法,画任意两点间的直线
- parameter:起点坐标(x0,y0),终点坐标(x1,y1),color:1点亮0擦除
- return:none
- ***********************************************/
- void Draw_Line(const uchar x0,const uchar y0,const uchar x1,const uchar y1,const uchar color)
- {
- int dx;
- int dy;
- char dx_sym;
- char dy_sym;
- int dx_2;
- int dy_2;
- int di;//决策变量
-
- dx=x1-x0;
- dy=y1-y0;
-
- if(dx<0)
- dx_sym=-1;
- else
- {
- if(dx>0)
- dx_sym=1;
- else
- {
- Draw_CollumLine(x0,y0,y1,color);
- return;
- }
- }
- if(dy<0)
- dy_sym=-1;
- else
- {
- if(dy>0)
- dy_sym=1;
- else
- {
- Draw_RowLine(x0,x1,y0,color);
- return;
- }
- }
- dx=dx_sym*dx;
- dy=dy_sym*dy;
- dx_2=dx*2;
- dy_2=dy*2;
- if(dx>=dy)
- {
- di=dy_2-dx;
- while(x0!=x1)
- {
- Draw_Point(x0,y0,color);
- x0+=dx_sym;
- if(di<0)
- di+=dy_2;
- else
- {
- di+=dy_2-dx_2;
- y0+=dy_sym;
- }
- }
- Draw_Point(x0,y0,color);
- }
- else
- {
- di=dx_2-dy;
- while(y0!=y1)
- {
- Draw_Point(x0,y0,color);
- y0+=dy_sym;
- if(di<0)
- di+=dx_2;
- else
- {
- di+=dx_2-dy_2;
- x0+=dx_sym;
- }
- }
- Draw_Point(x0,y0,color);
- }
- }
- /*******************************************
复制代码
|
|