/
display.c
69 lines (56 loc) · 1.92 KB
/
display.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
69
/*
* File: display.c
* Author: standard
*
* Created on 2023年9月10日, 下午3:10
*/
#include <xc.h>
#include "common.h"
#include "display.h"
char UART1_init(const long int baudrate){
unsigned int x;
x = (_XTAL_FREQ - baudrate*64)/(baudrate*64); //SPBRG for Low Baud Rate
if(x>255){ //If High Baud Rage Required{
x = (_XTAL_FREQ - baudrate*16)/(baudrate*16); //SPBRG for High Baud Rate
SPBRGH1 = (x >> 8) & 0xFF;
SPBRG1 = x & 0xFF;
BAUDCON1bits.BRG16 = 1;//Setting High Baud Rate
} else {
BAUDCON1bits.BRG16 = 0;
SPBRG1 = x & 0xFF;
}
TXSTA1bits.SYNC = 0; //Setting Asynchronous Mode, ie UART
RCSTA1bits.SPEN = 1; //Enables Serial Port
TRISCbits.TRISC7 = 1; //As Prescribed in Datasheet
TRISCbits.TRISC6 = 1; //As Prescribed in Datasheet
RCSTA1bits.CREN = 1; //Enables Continuous Reception
TXSTA1bits.TXEN = 1; //Enables Transmission
return 1; //Returns 0 to indicate UART initialization failed
}
void display_putchar(char data){
while(!TXSTA1bits.TRMT);
TXREG1 = data;
}
void display_output_line(char line){
for(char i=0; i<20; i++){
display_putchar(display_framebuffer[line][i]);
}
}
void display_refresh(){
display_putchar(0xFE);
display_putchar(0x46); // clear screen
display_output_line(0);
display_output_line(2);
display_output_line(1);
display_output_line(3);
}
void display_set_line(char line, char data[]){
line = line % 4;
for(char i=0; i<20; i++){
if(data[i] == '\0') break;
display_framebuffer[line][i] = data[i];
}
}
void display_init(void) {
UART1_init(9600);
}