Solar panel
Loading...
Searching...
No Matches
lcd.c
Go to the documentation of this file.
1/*
2 * File: lcd.c
3 * Author: pascal.sartoret
4 *
5 * Created on 16. décembre 2020, 14:04
6 */
7
8#define _XTAL_FREQ 25000000L
9
10#include <xc.h>
11#include <string.h>
12#include "lcd.h"
13#include "ssd1963_cmd.h"
14
15
16
17int8_t Lcd_Init(void)
18{
19 //--------------------------------------------------------------------------
20 // define GPIO for LCD
21 DIR_LCD_RS = 0; // RS is an output
22 LCD_RS = 0; // command mode
23 DIR_LCD_CS = 0; // chip select is an output
24 LCD_CS = 0; // do not select the LCD
25 LCD_DATA_L_DIR = LCD_DATA_L_DIR & 0x0F; // data port is 4 bits output
26
27 __delay_ms(200); // power on delay
29
31// LCD_2x16_WriteCmd(0x2B);
32// LCD_2x16_WriteCmd(0x2B);
33 LCD_2x16_WriteCmd(0x01); // clear display
35// LCD_2x16_WriteCmd(0x14);
36// __delay_ms(2);
38// __delay_ms(100);
39 return 0;
40}
41
42
43void LCD_2x16_WriteCmd(uint8_t command)
44{
45 LCD_RS = 0; // command mode
46 LCD_DATA_L = (command & 0xF0) | (LCD_DATA_L & 0x0F); // bits to set
47 LCD_CS = 1; // chip select
48 __delay_us(10);
49 LCD_CS = 0; // chip deselect
50 __delay_us(1);
51 command = command << 4;
52 LCD_DATA_L = (command & 0xF0) | (LCD_DATA_L & 0x0F); // bits to set
53 LCD_CS = 1; // chip select
54 __delay_us(10);
55 LCD_CS = 0; // chip deselect
56 __delay_ms(3);
57}
58void LCD_2x16_WriteData(uint8_t command)
59{
60 LCD_RS = 1; // command mode
61 LCD_DATA_L = (command & 0xF0) | (LCD_DATA_L & 0x0F); // bits to set
62 LCD_CS = 1; // chip select
63 __delay_us(1);
64 LCD_CS = 0; // chip deselect
65 __delay_us(1);
66 command = command << 4;
67 LCD_DATA_L = (command & 0xF0) | (LCD_DATA_L & 0x0F); // bits to set
68 LCD_CS = 1; // chip select
69 __delay_us(1);
70 LCD_CS = 0; // chip deselect
71 __delay_us(100);
72}
73
74void LCD_2x16_WriteMsg(unsigned char * msg, uint8_t line)
75{
76 LCD_2x16_WriteCmd(0x80 | (line << 6));
77 do
78 {
80 msg++;
81 }while(*msg != 0);
82}
void LCD_2x16_WriteData(uint8_t command)
Definition: lcd.c:58
void LCD_2x16_WriteCmd(uint8_t command)
Definition: lcd.c:43
int8_t Lcd_Init(void)
Definition: lcd.c:17
void LCD_2x16_WriteMsg(unsigned char *msg, uint8_t line)
Definition: lcd.c:74
#define LCD_DATA_L_DIR
Definition: lcd.h:42
#define DIR_LCD_RS
Definition: lcd.h:39
#define DIR_LCD_CS
Definition: lcd.h:41
#define LCD_RS
Definition: lcd.h:38
#define LCD_CS
Definition: lcd.h:40
#define LCD_DATA_L
Definition: lcd.h:43
SSD1963 Display Controller Commands.