📄 test.c
字号:
#include <absacc.h>
#include <reg51.h>
#include <string.h>
#include <intrins.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <intrins.h>
#include "ascii16.h"
#include "t6963c.h"
#define LCD_CURSOR_POSITION 0x21
#define LCD_CGRAM_POSITION 0x22
#define LCD_ADDRESS_POINTER 0x24
#define LCD_TXT_HOME_ADDRESS 0x40
#define LCD_TXT_AREA 0x41
#define LCD_GRAPHIC_ADDRESS 0x42
#define LCD_GRAPHIC_AREA 0x43
#define LCD_MOD_AND 0x83
#define LCD_MOD_OR 0X80
#define LCD_DISPLAY_SWITCH 0x9F /* Graphic on, Text on, Cursor on, Blink on */
#define LCD_CURSOR_SHAPE 0xA0
#define LCD_AUTO_WRITE 0xB0
#define LCD_ATUO_READ 0xB1
#define LCD_AUTO_OVER 0xB2
#define LCD_WR_ADP_INCREMENT 0xC0
#define LCD_RD_ADP_INCREMENT 0xC1
#define LCD_WR_ADP_DECREMENT 0xC2
#define LCD_RD_ADP_DECREMENT 0xC3
#define LCD_WR_ADP_NO_CHANGE 0xC4
#define LCD_RD_ADP_NO_CHANGE 0xC5
#define LCD_SCREEN_READ 0xE0
#define LCD_SCREEN_COPY 0xE8
#define GRAPHIC_HIGH_ADDRESS 0x3000
#define MOVE_UP_SCREEN 0x0
#define MOVE_DOWN_SCREEN 0x1
#define LCD_COMMAND 1
#define LCD_DATA 0
#define SET_POINT 1
#define CLEAR_POINT 0
#define LCD_DAT_ADDR 0xC000
#define LCD_COM_ADDR 0xC001
unsigned int graph_add;
sbit A_16 = P1^4;
sbit A_17 = P1^5;
sbit A_18 = P1^6;
sbit lcd_reset = P1^0;
sbit A_19 = P1^7;
void rd_status (uchar bit_number)
{
bit_number = bit_number;
watch_dog = ~watch_dog;
/*
uchar data c;
uchar cnt = 0;
while (cnt < 20) {
watch_dog = ~watch_dog;
c = XBYTE[LCD_COM_ADDR];
if ((1 == bit_number) && (3 == (c & 3)))
return ;
if ((3 == bit_number) && (c & 8))
return ;
cnt++;
}
return ;
*/
}
void wr_data(bit com_or_da, uchar data_or_command)
{
if (com_or_da == LCD_COMMAND) {
XBYTE[LCD_COM_ADDR]=data_or_command;
} else if (com_or_da == LCD_DATA) {
XBYTE[LCD_DAT_ADDR]=data_or_command;
}
return ;
}
void double_parameter (uchar first, uchar second, uchar command)
{
rd_status(1);
wr_data(LCD_DATA, first);
rd_status(1);
wr_data(LCD_DATA, second);
rd_status(1);
wr_data(LCD_COMMAND, command);
return ;
}
void single_parameter(uchar first, uchar command)
{
rd_status(1);
wr_data(LCD_DATA, first);
rd_status(1);
wr_data(LCD_COMMAND, command);
return ;
}
void no_parameter(uchar command)
{
rd_status(1);
wr_data(LCD_COMMAND, command);
return ;
}
void clear_LCD (void)
{
uint i;
double_parameter(0x00, 0x00,LCD_ADDRESS_POINTER);
no_parameter(LCD_AUTO_WRITE);
for (i = 0; i < 0x5000; i++)
{
rd_status(3);
wr_data(LCD_DATA, 0x00);
}
no_parameter(LCD_AUTO_OVER);
return ;
}
/*
//内置ASCII
void display_char(uchar p, uchar y, uchar x)
{
uint c;
c = y * 0x1e + x;
double_parameter(c, c >> 8, LCD_ADDRESS_POINTER);
single_parameter(p, LCD_WR_ADP_INCREMENT);
}
*/
void cursor(uchar o_y, uchar o_x)
{
double_parameter(o_x, o_y, LCD_CURSOR_POSITION);
}
void disable_cursor(void)
{
cursor(8, 0);
}
void clear_screen (void)
{
uint xdata i;
// bit ea_save;
// ea_save = EA;
ET0 = 0;
disable_cursor();
// EA = 0;
double_parameter(0x00, GRAPHIC_HIGH_ADDRESS >> 8, LCD_ADDRESS_POINTER);
// EA = ea_save;
no_parameter(LCD_AUTO_WRITE);
for (i = 0; i < 0x1680; i++) {
rd_status(3);
wr_data(LCD_DATA, 0x00);
}
no_parameter(LCD_AUTO_OVER);
graph_add = GRAPHIC_HIGH_ADDRESS;
double_parameter(0x00, GRAPHIC_HIGH_ADDRESS >> 8, LCD_GRAPHIC_ADDRESS);
ET0 = 1;
return ;
}
void display_ascii(uint o_y, uint o_x, uchar ascii_value, unsigned char disp_method)
{
uchar i;
unsigned int address, j;
if ((o_x > 29) || (ascii_value > 127)) {
return ;
}
address = GRAPHIC_HIGH_ADDRESS + o_y * 0x1e0 + o_x;
for (i = 0; i < 16; i ++) {
j = address + i * 0x1e;
double_parameter(j & 0xff, j >> 8, LCD_ADDRESS_POINTER);
if (disp_method == 0) {//正常显示
single_parameter(ASCII[ascii_value][i], LCD_WR_ADP_INCREMENT);
} else if (disp_method == 1) {//反白显示
single_parameter(~(ASCII[ascii_value][i]), LCD_WR_ADP_INCREMENT);
} else if (disp_method == 2) {//加下划线
if (i != 15) {
single_parameter(ASCII[ascii_value][i], LCD_WR_ADP_INCREMENT);
} else {
single_parameter(0xff, LCD_WR_ADP_INCREMENT);
}
}
}
return ;
}
void display_han(uchar o_y, uchar o_x, uchar *hanzi, unsigned char disp_method)
{
unsigned long data offset;
idata unsigned long ss;
idata unsigned int address, j;
uchar data i;
uchar matrix[32];
uchar data t;
// bit ea_save;
if (o_x > 29) {
return ;
}
//计算GB2312汉字首地址公式:
//汉字首地址= ((区码- 0xA1)×94 + 位码- 0xA1) ×32
offset = ((hanzi[0] - 0xA1) * 94 + (hanzi[1] - 0xA1));
offset *= 32;
for (i = 0; i < 32; i++) {
ss = (offset + i) & 0x10000;
A_16 = ss > 0;
ss = (offset + i) & 0x20000;
A_17 = ss > 0;
ss = (offset + i) & 0x40000;
A_18 = ss > 0;
// ea_save = EA;
// EA = 0;
ES = 0;
ET0 = 0;
A_19 = 0;
t = XBYTE[(unsigned int)(offset + i)];
A_19 = 1;
ES = 1;
ET0 = 1;
// EA = ea_save;
if (disp_method) {
t = ~t;
}
matrix[i] = t;
}
address = GRAPHIC_HIGH_ADDRESS + o_y * 0x1e0 + o_x;
for (i = 0; i < 32; i = i + 2) {
j = address + (i / 2) * 0x1e;
double_parameter(j & 0xff, j >> 8, LCD_ADDRESS_POINTER);
single_parameter(matrix[i], LCD_WR_ADP_INCREMENT);
single_parameter(matrix[i + 1], LCD_WR_ADP_INCREMENT);
}
return ;
}
uchar display(uchar y, uchar x, uchar *buffer, uchar length, uchar method)
{
idata unsigned int i;
idata unsigned short neima;
idata unsigned char m, n;
if ((x > 29) || (y > 15)) {
return 0;
}
if (length == 0) {
return 0;
}
if ((x + length) > 30) {
length = 30 - x;
}
for (i = 0; i < length;) {
if ((buffer[i] & 0x80) == 0) {
display_ascii(y, x, buffer[i], method);
x++;
i++;
} else {
m = buffer[i];
i++;
n = buffer[i];
i++;
neima = (m << 8) | n;
if (x == 29) {
return 1;
}
display_han(y, x, (unsigned char *)&neima, method);
// x++;
// x++;
x += 2;
}
}
return 0;
}
/*
void display_point(uchar method, uchar y, uchar x)
{
uint data address;
address = y * 30 + x /8 + GRAPHIC_HIGH_ADDRESS;
double_parameter(address & 0xff, address >> 8, LCD_ADDRESS_POINTER);
if (method == SET_POINT) {
no_parameter(0xf8 | ((~(x % 8)) & 0x07));
} else {
no_parameter(0xf0 | (x % 8));
}
return ;
}
void display_rectangle(uchar ystart, uchar yend, uchar xstart, uchar xend)
{
uchar i;
for (i = ystart; i <= yend; i++) { //两垂直线
display_point(SET_POINT, i, xstart);
display_point(SET_POINT, i, xend);
}
for (i = xstart; i <= xend; i++) { //两水平线
display_point(SET_POINT, ystart, i);
display_point(SET_POINT, yend, i);
}
return ;
}
void clear_rectangle(uchar ystart, uchar yend, uchar xstart, uchar xend)
{
uchar i;
for (i = ystart; i <= yend; i++) { //两垂直线
display_point(CLEAR_POINT, xstart, i);
display_point(CLEAR_POINT, xend, i);
}
for (i = xstart; i <= xend; i++) { //两水平线
display_point(CLEAR_POINT, i, ystart);
display_point(CLEAR_POINT, i, yend);
}
return ;
}
*/
void init_LCD (void)
{
unsigned int temp;
lcd_reset = 0;
for(temp = 0; temp < 3000; temp++)
watch_dog = ~watch_dog;
lcd_reset = 1;
for(temp = 0; temp < 30; temp++)
watch_dog = ~watch_dog;
clear_LCD();
double_parameter(0x00, 0x01, LCD_TXT_HOME_ADDRESS);
double_parameter(0x00, GRAPHIC_HIGH_ADDRESS >> 8, LCD_GRAPHIC_ADDRESS);
double_parameter(0x1e, 0x00, LCD_TXT_AREA);
double_parameter(0x1e, 0x00, LCD_GRAPHIC_AREA);
double_parameter(0x1c, 0x00, LCD_CGRAM_POSITION);
no_parameter(LCD_CURSOR_SHAPE);
no_parameter(LCD_MOD_OR);
no_parameter(LCD_DISPLAY_SWITCH);
graph_add = GRAPHIC_HIGH_ADDRESS;
return ;
}
/*
void main( void )
{
RS0 = 0;
RS1 = 0;
SP = 0x50;
init_LCD();
clear_LCD();
display(1, 3, "山东康威通信技术有限公司", 24, 0);
display(2, 6, "版权所有 技术支持", 18, 0);
display_rectangle(0, 63, 0, 239);
while (1) {
watch_dog = ~watch_dog;
}
return;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -