-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLCD.c
68 lines (66 loc) · 1.53 KB
/
LCD.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* LCD.c
*
* Created on: 29/4/2021
* Author: Muhab
*/
#include "StdTypes.h"
#include "Dio.h"
#include "LCD.h"
#include <string.h>
#include <avr/delay.h>
void LCD_Init(void){
DIO_vidSetPortDir(CONTROL_PORT,0xff);
DIO_vidSetPortDir(DATA_PORT,0xff);
LCD_sendcommand(FUNC_SET8);
_delay_ms(1);
LCD_sendcommand(DISP_ON);
_delay_ms(1);
LCD_sendcommand(CLEAR_DSIP);
_delay_ms(1);
LCD_sendcommand(ENTRY_MODE);
_delay_ms(1);
LCD_sendcommand(RETURN_HOME);
}
void LCD_sendcommand(u8 command){
DIO_vidWriteOnPin(CONTROL_PORT,0,0); //RS=0
DIO_vidWriteOnPin(CONTROL_PORT,1,0);// R/W=0
_delay_ms(1);
DIO_vidWriteOnPin(CONTROL_PORT,2,1);//Enable =1
_delay_ms(1);
DIO_vidWriteOnPort(DATA_PORT,command);
_delay_ms(1);
DIO_vidWriteOnPin(CONTROL_PORT,2,0);//Enable =0
_delay_ms(1);
DIO_vidWriteOnPin(CONTROL_PORT,2,1); //ENABLE =1
_delay_ms(1);
}
void LCD_sendchar(u8 data){
DIO_vidWriteOnPin(CONTROL_PORT,0,1); //RS=1
_delay_ms(1);
DIO_vidWriteOnPin(CONTROL_PORT,1,0); // R/W=0
_delay_ms(1);
DIO_vidWriteOnPin(CONTROL_PORT,2,1); //EN=1
_delay_ms(1);
DIO_vidWriteOnPort(DATA_PORT,data);
_delay_ms(1);
DIO_vidWriteOnPin(CONTROL_PORT,2,0); //EN=0
_delay_ms(1);
DIO_vidWriteOnPin(CONTROL_PORT,2,1); //EN=1
}
void LCD_sendstring(u8 *arr){
u8 i=0;
while(arr[i]!='\0'){
LCD_sendchar(arr[i]);
_delay_ms(500);
i++;
}
}
void LCD_clearlcd(void){
LCD_sendcommand(CLEAR_DSIP);
}
void LCD_sendnumber(u16 number){
u8 str1[16];
itoa(number,str1,10);
LCD_sendstring(str1);
}