📄 hcs12_12232f_lcd.c
字号:
/* hcs12_12232F_LCD.c */
#include "rtc.h"
#include "signal_out.h"
#include "sleep.h"
#include "com_interface.h"
#define _LCD_DATA_TO_SENT (3)
typedef struct {
U8 data[_LCD_DATA_TO_SENT]; //3 bytes
} SYN_SCI_SD_SMALL_TYPE;
////////////////////////////////////////////////////////////////////////////
// DEFINITIONS
////////////////////////////////////////////////////////////////////////////
#define LCD_WRITE_CMD 0xF8
#define LCD_WRITE_DATA 0xFA
#define LCD_READ_STATUS 0xFC
#define LCD_READ_DATA 0xFE
#define LCD_BUFFER_SIZE 64//32 //set/get time + set/get alarm
#define LCD_CHANNEL 1
typedef struct {
U8 head;
U8 tail;
SYN_SCI_SD_SMALL_TYPE lcd_rcv[LCD_BUFFER_SIZE];
} LCD_DATA_TYPE;
static LCD_DATA_TYPE lcd_data;
static void lcd_task(void);
static void lcd_send(void);
//static void lcd_parse(void);
static void add2send(SYN_SCI_SD_SMALL_TYPE * reg);
static void fill_a_byte(U8 * buf, U8 data);
static void fill_block(U8* data, U8 loc, U8 size);
static void fill_a_few_100(U8 * data, U8 v);
static void fill_a_few_10s(U8 * data, int v);
static U8 print_4bits(U8 v);
static long sm_timeout;
static RTOS_SEM_ID semrenew;
/***************************************************************************
Function name: rtc_Init
***************************************************************************/
void lcd_Init(void)
{
SYN_SCI_SD_SMALL_TYPE reg;
//U32 cnt;
semrenew = rtos_semBCreate(0, SEM_EMPTY);
sm_timeout = 5;//40 ms at leastWAIT_FOREVER;
lcd_data.head = lcd_data.tail = 0;
rtos_taskSpawn(RTOS_PEND_FOREVER_PRI+1, (RTOS_FUNCPTR) lcd_send, 0);
//wait 40 ms
/*
cnt = Timer.tcnt.word;
while(cnt < Timer.tcnt.word && Timer.tcnt.word-cnt < 30000) {
Crg.armcop = 0x55;
Crg.armcop = 0xAA;
} */
// reg.to_sd = 3;
reg.data[0] = LCD_WRITE_CMD;
fill_a_byte(®.data[1],0x30);
add2send(®);
fill_a_byte(®.data[1],0x0c);
add2send(®);
fill_a_byte(®.data[1],0x01);
add2send(®);
fill_a_byte(®.data[1],0x02);
add2send(®);
}
static void add2send(SYN_SCI_SD_SMALL_TYPE * reg)
{
U8 m = lcd_data.tail+1;
int n;
if (m == LCD_BUFFER_SIZE) {
m = 0;
}
for(n = 0; n < _LCD_DATA_TO_SENT; n++)
lcd_data.lcd_rcv[lcd_data.tail].data[n] = reg->data[n];
if (m == lcd_data.head) {
if (++lcd_data.head == LCD_BUFFER_SIZE) lcd_data.head = 0;
} //return; // buffer is full
lcd_data.tail = m;
if (sm_timeout == (long) WAIT_FOREVER) {
sm_timeout = 1;
rtos_semGive(semrenew);
}
}
#define LCD_CE_ON(on_off) (Pim.pth.bit.pth7 = (on_off) ? 1 : 0)
#define LCD_SCLK(on_off) (Pim.pth.bit.pth6 = (on_off) ? 1 : 0)
#define LCD_SID(on_off) (Pim.pth.bit.pth5 = (on_off) ? 1 : 0)
static void send_a_byte(U8 byte)
{
U8 n;//, k;
U8 bit = 0x80;
for(n = 0; n < 8; n++) {
LCD_SID(byte&bit);
/*for(k = 0; k < 10; k++) */LCD_SCLK(0);
/*for(k = 0; k < 10; k++) */LCD_SCLK(1);
bit >>= 1;
}
}
static void lcd_send(void)
{
U8 n;
long results = rtos_semTake(semrenew, sm_timeout);
if (lcd_data.head == lcd_data.tail || results == (long) OK) {
return;
}
sm_timeout = 1;
LCD_CE_ON(1); //CE enable
LCD_SCLK(0);
for(n = 0; n < _LCD_DATA_TO_SENT; n++) {
send_a_byte(lcd_data.lcd_rcv[lcd_data.head].data[n]);
}
LCD_CE_ON(0); //CE disable
lcd_data.head++;
if (lcd_data.head == LCD_BUFFER_SIZE) {
lcd_data.head = 0;
}
if (lcd_data.head == lcd_data.tail) { //continue to send till the buffer is empty
//rtos_semGive(smid);
sm_timeout = WAIT_FOREVER;
}
}
static void fill_a_byte(U8 * buf, U8 data)
{
buf[0] = data & 0xF0;
buf[1] = ((data << 4) & 0xF0);
}
static void fill_block(U8* data, U8 loc, U8 size)
{
SYN_SCI_SD_SMALL_TYPE reg;
U8 n;
reg.data[0] = LCD_WRITE_CMD;
fill_a_byte(®.data[1],loc); //location
add2send(®);
reg.data[0] = LCD_WRITE_DATA;
for(n = 0; n < size; n++) {
fill_a_byte(®.data[1],data[n]); //data
add2send(®);
}
}
static void fill_a_few_100(U8 * data, U8 v)
{
data[0] = (U8) (0x30+v/100);
data[1] = (U8) (0x30+(v%100)/10);
data[2] = (U8) (0x30+v%10);
}
static void fill_a_few_10s(U8 * data, int v)
{
data[0] = (U8) (0x30+(v%100)/10);
data[1] = (U8) (0x30+v%10);
}
void displaySpeedInLCD(U8 speed)
{
U8 speed_display[] = {
0xCB,0xD9,0xB6,0xC8,0x3A,
0,0,0
};
fill_a_few_100(&speed_display[5],speed);
fill_block(speed_display,0x93,8);
}
void displayDateInLCD(void)
{
struct tm * tms = getRTCTime();
U8 date[] = {
0,0,0x3A,0,0
};
UTC_to_Local(tms, 8);
fill_a_few_10s(&date[0], (U8) (tms->tm_hour));
fill_a_few_10s(&date[3], (U8) (tms->tm_min));
fill_block(date,0x90,5);
}
static U8 print_4bits(U8 v)
{
if (v < 10)
return (0x30+v);
else
return (0x41+(v-10));
}
void display_fill_raw_data(U8* des, U8 * src, int size)
{
int n;
for(n = 0; n < size; n++) {
des[2*n] = print_4bits((U8)(src[n] >> 4));
des[2*n+1] = print_4bits((U8)(src[n] & 0x0F));
}
}
void displayDriverInLCD(U32 ids)
{
U8 data[] = {
0xCB,0xBE,0xBB,0xFA,0xBA,0xC5,0x3A,
0,0,0,0,0,0,0x20,0x20
};
U8 * id = (U8*) &ids;
display_fill_raw_data(&data[7],&id[1],3);
fill_block(data,0x80,15);
}
void display_line(U8 * msgs, U8 size, U8 line)
{
if (line == 1) {
fill_block(msgs,0x80,size);
} else if (line == 2) {
fill_block(msgs,0x90,size);
}
}
void clear_screen(void)
{
SYN_SCI_SD_SMALL_TYPE reg;
reg.data[0] = LCD_WRITE_CMD;
fill_a_byte(®.data[1],1);
add2send(®);
}
void displayShortMsg(char * info)//displaySelfTest(void)
{
U8 data[] = {
0xD7,0xD4,0xBC,0xEC,0x2e,0x2e,0x2e,0x20
};
clear_screen();
if (info == NULL)
fill_block(data,0x80,8);
else
fill_block((U8*) info,0x80,(U8)_strlen(info,14));
}
int print_a_time(U32 * sec, U8 * date, U8 date_on, U8 clock_on)
{
int size = 0;
struct tm tms;
getTimeFromCOM_LOCATION(&tms, sec);
UTC_to_Local(&tms, 8);
if (date_on) {
date[size++] = '(';
fill_a_few_10s(&date[size], tms.tm_year); size+=2;
date[size++] = '/';
fill_a_few_10s(&date[size], tms.tm_mon+1); size+=2;
date[size++] = '/';
fill_a_few_10s(&date[size], tms.tm_mday+1); size+=2;
date[size++] = ')';
}
if (clock_on) {
date[size++] = 0x20;
fill_a_few_10s(&date[size], tms.tm_hour); size+=2;
date[size++] = 0x3a;
fill_a_few_10s(&date[size], tms.tm_min); size+=2;
date[size++]=0x20;
date[size++]=0x20; //
}
return size;
}
//End of File hcs12_12232F_LCD.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -