Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f10x.h"
- #include "stm32f10x_tim.h"
- #include "stm32f10x_rcc.h"
- #include "stm32f10x_gpio.h"
- #include "stm32f10x_usart.h"
- #include "misc.h"
- #include "stm32f10x_exti.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdint.h>
- #include <time.h>
- USART_InitTypeDef USART_InitStruct; // this is for the USART1 initilization
- GPIO_InitTypeDef GPIO_InitStructure;
- void GPIO_Config(void);
- void init_USART1(uint32_t baudrate);
- void USART_puts(USART_TypeDef* USARTx, volatile char *s);
- #define EN GPIO_Pin_10
- #define RS GPIO_Pin_12
- #define RW GPIO_Pin_11
- /***************************************************************************//**
- * Declare function prototypes
- ******************************************************************************/
- void RCC_Configuration(void);
- void LCD_DATA_DIR_OUT(void);
- void LCD_DATA_DIR_IN(void);
- void LCD_ALL_DIR_OUT(void);
- unsigned int LCD_DATA_IN(void);
- static unsigned char Wait_While_Busy(void);
- static unsigned char Lcd_Read_Status (void);
- void Lcd_Write_4bits(uc8 byte);
- void Delay(vu32 nCount);
- void Lcd_Write_Command(uc8 command);
- void Lcd_Write_Data(uc8 data);
- void Lcd_Init(void);
- void Lcd_Write_Line1(void);
- void Lcd_Write_Line2(void);
- void set_cursor(int, int);
- void lcd_print (char *string);
- void lcd_clear (void);
- // **** IN Time
- char textSecond[100] = "",textMinute[100] = "",textHour[100] = "";
- char text[100] = "",text2[100] = "",text3[100] = "",text4[100] = "";
- // Wait Change to loop
- char Date1[100] = "",Date2[100] = "",Date3[100] = "",Date4[100] = "";
- char Date5[100] = "",Date6[100] = "",Date7[100] = "",Date8[100] = "";
- // Seperate Int to Char each bit
- char sepSecond[10],sepMinute[10],sepHour[10];
- char checkOut[100] = "",data[100];
- int i = 0,j = 0;
- int count =0,state = 0;
- uint32_t last_time = 0,temp_time = 0,temp = 0; //store data to check
- int value,value1,value2,value3,value4;
- char valueS[100] = "";
- int tempValue,column,row,loop1 = 0;
- // constant values
- const int ROWS = 4;
- const int COLS = 4;
- int keys[4][4] = {{'1','2','3','A'},{'4','5','6','B'},{'7','8','9','C'},{'*','0','#','D'}};
- int input[4] = {((uint16_t)0x0010),((uint16_t)0x0020),((uint16_t)0x0040),((uint16_t)0x0080)};
- int output[4] = {((uint16_t)0x0004),((uint16_t)0x0020),((uint16_t)0x0040),((uint16_t)0x0080)};
- int rowPins[4] = {0,1,2,3}; // connect B0,1,2,3 to Rows 1-4 (the left four pins)
- int colPins[4] = {0,1,2,3}; // connect A0,1,2,3 to Column 1-4 (the right four pins)
- #define A_PORT GPIOA
- #define B_PORT GPIOB
- int key, loopLCD,loopTime;
- char checkLast[10];
- void GPIO_LCD1602(void);
- int main(void)
- {
- int tempValue;
- char* strTime[4];
- char* strDate[8];
- strTime[2] = "Set : ";
- char* strings[60];
- // *** For check keypad + time
- int checkbit1,checkbit2,checkbit3,checkbit4;
- int shiftBitSecond,shiftBitMinute;
- // *** End Value check
- GPIO_Config();
- init_USART1(9600); // initialize USART1 @ 115200 baud
- RCC_Configuration();
- Lcd_Init();
- GPIO_WriteBit(B_PORT,GPIO_Pin_2,Bit_SET);
- GPIO_WriteBit(B_PORT,GPIO_Pin_5,Bit_SET);
- GPIO_WriteBit(B_PORT,GPIO_Pin_6,Bit_SET);
- GPIO_WriteBit(B_PORT,GPIO_Pin_7,Bit_SET);
- lcd_clear(); /* clean the LCD */
- Delay(1000);
- USART_puts(USART1, "Start!\r\n"); // just send a message to indicate that it works
- char* setTime[5];
- char* keepTime[5];
- int tempINT = 0,cLoop,var = 0,check = 0;
- char keep,inpass[ ] = "";
- int index = 0,iLoop;
- int countSecond = 0,countMinute = 0,countHour = 0;
- char checkString[10],b[10];
- uint8_t state = 0;
- int tempTimeSecond,tempTimeMinute,tempTimeHour;
- // **** Time by Time.h ****
- RCC_Configuration();
- Lcd_Init();
- lcd_clear();
- Delay(1000);
- // Main LCD do
- set_cursor(0,0);
- lcd_print ("Time = ");
- set_cursor(71, 0);
- lcd_print ("*D-M-Year");
- set_cursor(66, 0);
- lcd_print ("--:--");
- set_cursor(7,0);
- lcd_print ("0-:0-:--");
- // set_cursor(7,0);
- // lcd_print ("IC-DS1307");
- while (1)
- {
- // Set test real time **************
- sprintf (textSecond, "%02X", countSecond);
- set_cursor(13,0); /* set cursor */
- lcd_print (textSecond); /* display */
- countSecond = countSecond + 1;
- // Cut A-F
- tempTimeSecond = countSecond&0x0F;
- if(tempTimeSecond == 0x0A){
- countSecond = countSecond + 6;
- }
- // End Cut A-F
- if(countSecond == 0x60){
- countMinute = countMinute + 1;
- // Cut A-F
- tempTimeMinute = countMinute&0x0F;
- if(tempTimeMinute == 0x0A){
- countMinute = countMinute + 6;
- }
- // End Cut A-F
- sprintf (textMinute, "%02X", countMinute);
- set_cursor(10,0); /* set cursor */
- lcd_print (textMinute); /* display */
- set_cursor(14,0); /* set cursor */
- lcd_print ("-"); /* display */
- // countMinute = countMinute + 1;
- countSecond = 0;
- if(countMinute == 0x60){
- countHour = countHour + 1;
- // Cut A-F
- tempTimeHour = countHour&0x0F;
- if(tempTimeHour == 0x0A){
- countHour = countHour + 6;
- }
- // End Cut A-F
- sprintf (textHour, "%02X", countHour);
- set_cursor(7,0); /* set cursor */
- lcd_print (textHour); /* display */
- set_cursor(11,0); /* set cursor */
- lcd_print ("-"); /* display */
- //countHour = countHour + 1;
- countMinute = 0;
- if(countHour == 0x24){ // 24 Hours
- countHour = 0;
- }
- }
- }
- // End Set test real time ***********
- set_cursor(64, 0);
- lcd_print ("T=");
- value = getKey();
- set_cursor(68, 0); // *** set_cursor(64, 0); is Column 0 in row 1 ***
- lcd_print (":");
- if(value !=0){
- // First For Time
- if(count == 0){
- sprintf (text, "%c", value);
- USART_puts(USART1, text);
- }
- else if(count == 1){
- sprintf (text2, "%c", value);
- USART_puts(USART1, text2);
- }
- else if(count == 2){
- sprintf (text3, "%c", value);
- USART_puts(USART1, text3);
- }
- else if(count == 3){
- sprintf (text4, "%c", value);
- USART_puts(USART1, text4);
- // count = -1;
- }
- // Last For Time
- //First For Date ***
- else if(count == 4){
- sprintf (Date1, "%c", value);
- USART_puts(USART1, Date1);
- }
- else if(count == 5){
- sprintf (Date2, "%c", value);
- USART_puts(USART1, Date2);
- }
- else if(count == 6){
- sprintf (Date3, "%c", value);
- USART_puts(USART1, Date3);
- }
- else if(count == 7){
- sprintf (Date4, "%c", value);
- USART_puts(USART1, Date4);
- }
- // Year
- else if(count == 8){
- sprintf (Date5, "%c", value);
- USART_puts(USART1, Date5);
- }
- else if(count == 9){
- sprintf (Date6, "%c", value);
- USART_puts(USART1, Date6);
- }
- else if(count == 10){
- sprintf (Date7, "%c", value);
- USART_puts(USART1, Date7);
- }
- else if(count == 11){
- sprintf (Date8, "%c", value);
- USART_puts(USART1, Date8);
- count = -1;
- }
- // Last For Date ***
- count = count + 1;
- }
- // For Time is Hour : Minute
- strTime[0] = text;
- strTime[1] = text2;
- strTime[2] = text3;
- strTime[3] = text4;
- set_cursor(66, 0); // *** set_cursor(64, 0); is Column 0 in row 1 ***
- lcd_print (strTime[0]);
- set_cursor(67, 0); // *** set_cursor(64, 0); is Column 0 in row 1 ***
- lcd_print (strTime[1]);
- set_cursor(69, 0); // *** set_cursor(64, 0); is Column 0 in row 1 ***
- lcd_print (strTime[2]);
- set_cursor(70, 0); // *** set_cursor(64, 0); is Column 0 in row 1 ***
- lcd_print (strTime[3]);
- // For Date is Day : Month : Year
- strDate[0] = Date1;
- strDate[1] = Date2;
- strDate[2] = Date3;
- strDate[3] = Date4;
- strDate[4] = Date5;
- strDate[5] = Date6;
- strDate[6] = Date7;
- strDate[7] = Date8;
- set_cursor(72, 0); // *** set_cursor(64, 0); is Column 0 in row 1 ***
- lcd_print (strDate[0]);
- set_cursor(73, 0); // *** set_cursor(64, 0); is Column 0 in row 1 ***
- lcd_print (strDate[1]);
- set_cursor(74, 0); // *** set_cursor(64, 0); is Column 0 in row 1 ***
- lcd_print (strDate[2]);
- set_cursor(75, 0); // *** set_cursor(64, 0); is Column 0 in row 1 ***
- lcd_print (strDate[3]);
- set_cursor(76, 0); // *** set_cursor(64, 0); is Column 0 in row 1 ***
- lcd_print (strDate[4]);
- set_cursor(77, 0); // *** set_cursor(64, 0); is Column 0 in row 1 ***
- lcd_print (strDate[5]);
- set_cursor(78, 0); // *** set_cursor(64, 0); is Column 0 in row 1 ***
- lcd_print (strDate[6]);
- set_cursor(79, 0); // *** set_cursor(64, 0); is Column 0 in row 1 ***
- lcd_print (strDate[7]);
- // State Check Bit Real Time + Set Time
- checkbit1 = atoi(strTime[0]);
- checkbit2 = atoi(strTime[1]);
- checkbit3 = atoi(strTime[2]);
- checkbit4 = atoi(strTime[3]);
- // sprintf (sepSecond, "%d", countSecond); // is Char
- shiftBitMinute = (checkbit1<<4)+(checkbit2);
- shiftBitSecond = (checkbit3<<4)+(checkbit4);
- if(shiftBitSecond == countSecond && shiftBitMinute == countMinute){
- // if(countMinute == checkbit1 && countSecond == checkbit3 ){
- GPIO_WriteBit(B_PORT,GPIO_Pin_10,Bit_SET);
- }else{
- GPIO_WriteBit(B_PORT,GPIO_Pin_10,Bit_RESET);
- }
- // End State Check Bit Real Time + Set Time
- // For Test LED
- GPIO_WriteBit(B_PORT,GPIO_Pin_8,Bit_SET);
- for(i=0;i<0x100000;i++); // is 1 second
- set_cursor(9,0);
- lcd_print (":");
- set_cursor(12,0);
- lcd_print (":");
- // } // Close Loop is Change LoopLCD
- set_cursor(0, 1);
- lcd_print (" ");
- }
- }
- int j;
- int i;
- int getKey(void)
- {
- int key_pressed = 0;
- for (j=0; j < ROWS; j++) { // scan the j-th row (j=0,1,2,3)
- for (i=0; i < ROWS; i++) {
- // output HIGH to all rows, except the j-th row
- if(i==j){
- GPIO_WriteBit(B_PORT,output[i],Bit_RESET);
- }else{
- GPIO_WriteBit(B_PORT,output[i],Bit_SET);
- }
- }
- for (i=0; i < COLS; i++) {
- if(GPIO_ReadInputDataBit(GPIOA,input[i]) == 0){ // Button at (R,C)=(j,i) is pressed
- // wait until the button is released.
- while ( GPIO_ReadInputDataBit(GPIOA,input[i]) == 0 ) ; // blocking
- key_pressed = keys[j][i]; // get the associated key for that button
- break;
- }
- }
- GPIO_WriteBit(B_PORT,output[j],Bit_SET);
- if ( key_pressed != 0 ) {
- return key_pressed;
- }
- }
- return 0; // no key pressed
- }
- const unsigned int SWAP_DATA[16] = { 0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE,
- 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF};
- const char UserFont[8][8] = { /* 8 user defined characters to be loaded into CGRAM (used for bargraph)*/
- { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
- { 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10 },
- { 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18 },
- { 0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C },
- { 0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E },
- { 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F },
- { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
- { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }
- };
- void GPIO_Config(void)
- {
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_USART1 |
- RCC_APB2Periph_GPIOA, ENABLE);
- //INPUT A = COLUMN
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- //OUTPUT B = ROW
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 ;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- //USART1 (PA9)
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //USART1_TX
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- }
- void init_USART1(uint32_t baudrate){
- USART_InitStruct.USART_BaudRate = baudrate; // the baudrate is set to the value we passed into this init function
- USART_InitStruct.USART_WordLength = USART_WordLength_8b; // we want the data frame size to be 8 bits (standard)
- USART_InitStruct.USART_StopBits = USART_StopBits_1; // we want 1 stop bit (standard)
- USART_InitStruct.USART_Parity = USART_Parity_No; // we don't want a parity bit (standard)
- USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; // we don't want flow control (standard)
- USART_InitStruct.USART_Mode = USART_Mode_Tx; // we want to enable the transmitter and the receiver
- USART_Init(USART1, &USART_InitStruct); // again all the properties are passed to the USART_Init function which takes care of all the bit setting
- USART_ITConfig(USART1, USART_IT_RXNE, DISABLE); // enable the USART1 receive interrupt
- USART_Cmd(USART1, ENABLE);
- }
- void USART_puts(USART_TypeDef* USARTx, volatile char *s){
- while(*s){
- // wait until data register is empty
- while( !(USARTx->SR & 0x00000040) );
- USART_SendData(USARTx, *s);
- *s++;
- }
- }
- void GPIO_LCD1602(void)
- {
- //valueinLCD = getKey();
- RCC_Configuration();
- Lcd_Init(); /* initial */
- lcd_clear(); /* clean the LCD */
- Delay(1000);
- set_cursor(0,0); /* set cursor */
- lcd_print (" TestTest! "); /* display */
- set_cursor(0, 1);
- lcd_print (" SetTime ");
- }
- /***************************************************************************//**
- * @brief System clocks configuration
- ******************************************************************************/
- void RCC_Configuration(void)
- {
- RCC_DeInit (); /* RCC system reset(for debug purpose)*/
- RCC_HSEConfig (RCC_HSE_ON); /* Enable HSE */
- /* Wait till HSE is ready */
- while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);
- RCC_HCLKConfig (RCC_SYSCLK_Div1); /* HCLK = SYSCLK */
- RCC_PCLK2Config (RCC_HCLK_Div1); /* PCLK2 = HCLK */
- RCC_PCLK1Config (RCC_HCLK_Div2); /* PCLK1 = HCLK/2 */
- RCC_ADCCLKConfig (RCC_PCLK2_Div4); /* ADCCLK = PCLK2/4 */
- *(vu32 *)0x40022000 = 0x01; /* Flash 2 wait state */
- /* PLLCLK = 8MHz * 9 = 72 MHz */
- RCC_PLLConfig (0x00010000, RCC_PLLMul_9);
- RCC_PLLCmd (ENABLE); /* Enable PLL */
- /* Wait till PLL is ready */
- while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
- /* Select PLL as system clock source */
- RCC_SYSCLKConfig (RCC_SYSCLKSource_PLLCLK);
- /* Wait till PLL is used as system clock source */
- while (RCC_GetSYSCLKSource() != 0x08);
- }
- /***************************************************************************//**
- * @brief Delay some time
- ******************************************************************************/
- void Delay(vu32 nCount)
- {
- for(; nCount != 0; nCount--);
- }
- /***************************************************************************//**
- * @brief Setting all pins to output mode
- ******************************************************************************/
- void LCD_ALL_DIR_OUT(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- }
- /***************************************************************************//**
- * @brief Setting DATA pins to input mode
- ******************************************************************************/
- void LCD_DATA_DIR_IN(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- }
- /***************************************************************************//**
- * @brief Setting DATA pins to output mode
- ******************************************************************************/
- void LCD_DATA_DIR_OUT(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- }
- /***************************************************************************//**
- * @brief Reading DATA pins
- * @return the data value.
- ******************************************************************************/
- unsigned int LCD_DATA_IN(void)
- {
- uint16_t u16Temp=0;
- u16Temp = GPIO_ReadInputData(GPIOC)&0x000F;
- return SWAP_DATA[u16Temp];
- }
- /***************************************************************************//**
- * @brief Read status of LCD controller
- * @return status : Status of LCD controller
- ******************************************************************************/
- static unsigned char Lcd_Read_Status (void)
- {
- unsigned char status;
- LCD_DATA_DIR_IN();
- GPIO_WriteBit(GPIOC, RS, Bit_RESET);
- GPIO_WriteBit(GPIOC, RW, Bit_SET);
- Delay(10);
- GPIO_WriteBit(GPIOC, EN, Bit_SET);
- Delay(10);
- status = LCD_DATA_IN() << 4;
- GPIO_WriteBit(GPIOC, EN, Bit_RESET);
- Delay(10);
- GPIO_WriteBit(GPIOC, EN, Bit_SET);
- Delay(10);
- status |= LCD_DATA_IN();
- GPIO_WriteBit(GPIOC, EN, Bit_RESET);
- LCD_DATA_DIR_OUT();
- return (status);
- }
- /***************************************************************************//**
- * @brief Wait while LCD is busy
- * @return status : Status of LCD controller
- ******************************************************************************/
- static unsigned char Wait_While_Busy()
- {
- unsigned char status;
- do{
- status = Lcd_Read_Status();
- }while(status & 0x80);
- return status;
- }
- /***************************************************************************//**
- * @brief Write 4-bits to LCD controller
- ******************************************************************************/
- void Lcd_Write_4bits(uc8 byte)
- {
- uint16_t u16Temp=0;
- GPIO_WriteBit(GPIOC, RW, Bit_RESET);
- GPIO_WriteBit(GPIOC, EN, Bit_SET);
- u16Temp = GPIO_ReadOutputData(GPIOC)&0xFFF0;
- u16Temp |= SWAP_DATA[byte&0x0F];
- GPIO_Write(GPIOC, u16Temp);
- Delay(10);
- GPIO_WriteBit(GPIOC, EN, Bit_RESET);
- Delay(10);
- }
- /***************************************************************************//**
- * @brief: Write command to LCD controller
- * @param[in] command : Command to be written
- ******************************************************************************/
- void Lcd_Write_Command(uc8 command)
- {
- Wait_While_Busy();
- GPIO_WriteBit(GPIOC, RS, Bit_RESET);
- Lcd_Write_4bits(command>>4);
- Lcd_Write_4bits(command);
- }
- /***************************************************************************//**
- * @brief: Write data to LCD controller
- * @param[in] data : Data to be written
- ******************************************************************************/
- void Lcd_Write_Data(uc8 data)
- {
- Wait_While_Busy();
- GPIO_WriteBit(GPIOC, RS, Bit_SET);
- Lcd_Write_4bits(data>>4);
- Lcd_Write_4bits(data);
- }
- /*******************************************************************************
- * @brief : Set cursor position on LCD display
- * @param[in] column : Column position
- * @param[in] line : Line position
- *******************************************************************************/
- void set_cursor(int column, int line)
- {
- unsigned char address;
- address = (line * 40) + column;
- address = 0x80 + (address & 0x7F);
- Lcd_Write_Command(address); /* Set DDRAM address counter to 0 */
- }
- /***************************************************************************//**
- * @brief Initial the LCD1602
- ******************************************************************************/
- void Lcd_Init(void)
- {
- char const *p;
- int i;
- /* Enable clock for peripheral */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
- /* Set all pins for LCD as outputs */
- LCD_ALL_DIR_OUT();
- Delay(15000);
- GPIO_WriteBit(GPIOC, RS, Bit_RESET);
- Lcd_Write_4bits(0x3); /* Select 4-bit interface */
- Delay(4100);
- Lcd_Write_4bits(0x3);
- Delay(100);
- Lcd_Write_4bits(0x3);
- Lcd_Write_4bits(0x2);
- Lcd_Write_Command(0x28); /* 2 lines, 5x8 character matrix */
- Lcd_Write_Command(0x0C); /* Display ctrl:Disp=ON,Curs/Blnk=OFF */
- Lcd_Write_Command(0x06); /* Entry mode: Move right, no shift */
- /* Load user-specific characters into CGRAM */
- Lcd_Write_Command(0x40); /* Set CGRAM address counter to 0 */
- p = &UserFont[0][0];
- for (i = 0; i < sizeof(UserFont); i++, p++)
- lcd_print (*p);
- Lcd_Write_Command(0x80); /* Set DDRAM address counter to 0 */
- }
- /***************************************************************************//**
- * @brief print a string on LCD1602.
- * @param[in] *string : point to the string which will be printed on LCD.
- ******************************************************************************/
- void lcd_print (char *string)
- {
- int i;
- for (i=0;i<16 && string[i]!=0;i++) // 16 Character Print
- {
- Lcd_Write_Data(string[i]); // Print Byte to LCD
- }
- /*
- while (*string)
- {
- Lcd_Write_Data (*string++);
- }
- */
- }
- /*******************************************************************************
- * @brief Clear the LCD display *
- *******************************************************************************/
- void lcd_clear (void)
- {
- Lcd_Write_Command(0x01); /* Display clear */
- set_cursor (0, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement