|
下面给出程序:
- /*
- ******************************************************************************
- * File Name : Lcd.c
- * Author : dontium
- * Description : This file contains the procedure for the LCD 1602
- ******************************************************************************
- */
- #include "F051_hardwaer.h"
- #include "lcd.h"
- void LcdDelay(uint16_t dl)
- {
- uint16_t i;
- for ( i = 0; i < dl ; i++)
- {
- __asm ( " nop ");
- __asm ( " nop ");
- __asm ( " nop ");
- }
- }
- //mode: =0 write command, =1 write Data
- //dat
- void LcdWrite(uint8_t dat,uint8_t mode)
- {
- uint16_t temp;
- LcdDelay(500);
-
- LCD_RW_WRITE();
- if ( mode )
- LCD_RSDAT();
- else
- LCD_RSCOM();
- LCD_ENABLE();
-
- temp = (uint16_t) GPIOB->ODR;
- temp &= 0xFF00;
- temp |= dat;
- GPIOB->ODR = temp;
- LCD_DISABLE();
- LcdDelay(1);
- LCD_RW_READ();
-
- }
- //LCD1602 Initialization
- void LcdInit(void)
- {
- uint8_t i;
- Delay_mS(15);
- LcdWrite(0x38,0);//16*2 display,5*7 dot matrix,8bit port
- Delay_mS(10);
- LcdWrite(0x0f,0);//display on ,cursor start and flash
- Delay_mS(10);
- LcdWrite(0x06,0);// character Increment , Cursor Increment ,
- Delay_mS(10);
- LcdWrite(0x01,0);// clear
- for( i = 0 ; i < 16 ; i++)
- {
- table1[i] = i+0x30;
- table2[i] = i+0x40;
- }
- table1[2] = ':';
- table1[5] = ':';
-
- }
- void LcdClear(void)
- {
- LcdWrite(1,0);
- }
- void LcdReturn(void)
- {
- LcdWrite(2,0);
- }
- uint8_t table1[16],table2[16];
- //Cursor Location
- void lcd162a_LocateXY(uint8_t posx,uint8_t posy)
- {
- uint8_t temp;
- temp=posx & 0xf;
- posy &= 0x01;
- if(posy) temp |=0x40;
- temp |=0x80;
- LcdWrite(temp,0);
- }
- // Display a character
- //x:0~15
- //y:0~1
- void LcdWriteChar(void)//uint8_t x,uint8_t y,uint8_t Wdata)
- {
- uint8_t i;
- lcd162a_LocateXY(0,0);
- for ( i = 0 ; i < 16 ; i++ )
- {
- LcdWrite(table1[15-i],1);
- }
- lcd162a_LocateXY(0,1);
- for ( i = 0 ; i < 16 ; i++ )
- {
- LcdWrite(table2[i],1);
- }
- }
- /********************************* end file ***********************************/
复制代码
|
|