📄 main_program.c
字号:
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
#include "V_PLC.h"
#pragma DATA_SECTION(Lcd, "LCD" )
volatile struct LCD_REGS Lcd;
unsigned int lcd_cmd;
unsigned int i,j;
unsigned int screen_x,screen_y,state;
unsigned int sx,sy,tx,ty;
void main(void)
{ // int a= 5;
//int b=7;
// int c= a*b;
InitSysCtrl();
InitGpio();
DINT;
DRTM;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
InitCpuTimers();
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
//----------------------------------------------------------
//----------------------------------------------
// PLC扩展板初始化:
// 1、寄存器EXP_GPIO的第5位用于外部总线扩展使能
// 2、寄存器EXPCTR0,EXPCTR1,EXPCTR2,EXPCTR3用于
// 外部(PLC扩展板)存储器的页功能控制, 其中:
// 1)、每个寄存器控制4页;
// 2)、寄存器控制字低8位有效,每2位控制1页;
// 3)、从低到高,控制的对象依次是第1,2,3,4页;
// 4)、二进制值为01时,该页为输入,为10时输出;
// 5)、LCD_DEMO演示程序中只有显示功能,无PLC功能;
//----------------------------------------------
//*EXP_GPIO = 0x0020;
//*EXPCTR0 = 0x0056;
//----------------------------------------------
// 显卡芯片的时钟信号延时初始化
//----------------------------------------------
GpioDataRegs.GPADAT.bit.GPIOA5 = 0;
delay_100us(); delay_100us();
GpioDataRegs.GPADAT.bit.GPIOA5 = 1;
delay_10us();
/*
GpioDataRegs.GPEDAT.bit.GPIOE1 = 0;
delay_100us(); delay_100us();
GpioDataRegs.GPEDAT.bit.GPIOE1 = 1;
delay_10us();
*/
//----------------------------------------------
// 打开LCD的背光显示
// 初始化行列和斜线的自动加1功能的值
//----------------------------------------------
lcd_cmd = LCD_ON + DIS_PAGE0 + WR_PAGE0;
DelayMs(100);
ClrScreen(COLOR_GREEN,lcd_cmd);
Disp_word(472,26,26499,Hanz43);
// ClrScreen(COLOR_GREEN,lcd_cmd);
Disp_word(472,66,26499,hz12);
// ClrScreen(COLOR_GREEN,lcd_cmd);
// Disp_word(472,28,26499, ph188);
//============================================================================================
// 显示液晶屏最大边角-------------------------------------------------------------------------
/* Dot(0,0,COLOR_RED);
Dot(0,2,COLOR_RED);
Dot(0,3,COLOR_RED);
Dot(5,4,COLOR_RED);
Dot(5,5,COLOR_RED);
Dot(5,6,COLOR_RED);
Dot(5,7,COLOR_RED);
Dot(5,8,COLOR_RED);
Dot(5,9,COLOR_RED);
Dot(5,10,COLOR_RED);
Dot(5,11,COLOR_RED);
Dot(5,12,COLOR_RED);
Dot(5,13,COLOR_RED);
Dot(5,14,COLOR_RED);
Dot(5,15,COLOR_RED);*/
// Dot(1,0,COLOR_RED); Dot(2,0,COLOR_RED); Dot(3,0,COLOR_RED);
// Dot(799,0,COLOR_RED); Dot(799,1,COLOR_RED); Dot(799,2,COLOR_RED); Dot(799,3,COLOR_RED);
// Dot(796,0,COLOR_RED); Dot(797,0,COLOR_RED); Dot(798,0,COLOR_RED);
// Dot(0,599,COLOR_RED); Dot(0,598,COLOR_RED); Dot(0,597,COLOR_RED); Dot(0,596,COLOR_RED);
// Dot(1,599,COLOR_RED); Dot(2,599,COLOR_RED); Dot(3,599,COLOR_RED);
// Dot(799,599,COLOR_RED); Dot(799,598,COLOR_RED); Dot(799,597,COLOR_RED); Dot(799,596,COLOR_RED);
//Dot(798,599,COLOR_RED); Dot(797,599,COLOR_RED); Dot(796,599,COLOR_RED);
//=============================================================================================
DelayMs(3000);
//显示红色矩形---------------------------------------------------------------------------------
/* Line(33,40,600,40,COLOR_RED,lcd_cmd);
Line(33,41,33,435,COLOR_RED,lcd_cmd);
Line(33,436,600,436,COLOR_RED,lcd_cmd);
Line(601,40,601,436,COLOR_RED,lcd_cmd);
//显示蓝色矩形---------------------------------------------------------------------------------
Line(191,210,430,210,COLOR_BLUE,lcd_cmd);
Line(191,211,191,265,COLOR_BLUE,lcd_cmd);
Line(191,266,430,266,COLOR_BLUE,lcd_cmd);
Line(431,210,431,266,COLOR_BLUE,lcd_cmd);*/
//=============================================================================================
/* DelayMs(300);
lcd_cmd = LCD_ON + DIS_PAGE1 + WR_PAGE1;
DelayMs(500);
ClrScreen(COLOR_GREEN,lcd_cmd);
Line(56,70,575,70,COLOR_BLACK,lcd_cmd);
Line(56,69,56,405,COLOR_BLACK,lcd_cmd);
Line(56,406,575,406,COLOR_BLACK,lcd_cmd);
Line(576,70,576,405,COLOR_BLACK,lcd_cmd);
Line(79,100,550,100,COLOR_BLACK,lcd_cmd);
Line(79,99,79,375,COLOR_BLACK,lcd_cmd);
Line(79,376,550,376,COLOR_BLACK,lcd_cmd);
Line(551,100,551,375,COLOR_BLACK,lcd_cmd);
lcd_cmd = LCD_ON + DIS_PAGE2 + WR_PAGE2;
DelayMs(500);
ClrScreen(COLOR_GREEN,lcd_cmd);
Line(102,130,525,130,COLOR_YELLOW,lcd_cmd);
Line(102,129,102,345,COLOR_YELLOW,lcd_cmd);
Line(102,346,525,346,COLOR_YELLOW,lcd_cmd);
Line(526,130,526,345,COLOR_YELLOW,lcd_cmd);
Line(125,160,500,160,COLOR_YELLOW,lcd_cmd);
Line(125,159,125,315,COLOR_YELLOW,lcd_cmd);
Line(125,316,500,316,COLOR_YELLOW,lcd_cmd);
Line(501,160,501,315,COLOR_YELLOW,lcd_cmd);
lcd_cmd = LCD_ON + DIS_PAGE3 + WR_PAGE3;
DelayMs(500);
ClrScreen(COLOR_GREEN,lcd_cmd);
Line(148,190,475,190,COLOR_BLUE,lcd_cmd);
Line(148,189,148,285,COLOR_BLUE,lcd_cmd);
Line(148,286,475,286,COLOR_BLUE,lcd_cmd);
Line(476,190,476,285,COLOR_BLUE,lcd_cmd);
Line(171,220,450,220,COLOR_BLUE,lcd_cmd);
Line(171,219,171,255,COLOR_BLUE,lcd_cmd);
Line(171,256,450,256,COLOR_BLUE,lcd_cmd);
Line(451,220,450,256,COLOR_BLUE,lcd_cmd);*/
// Touch Screen
//----------------------------------------------------------
//== 1:touch in rectangle , change color
//== 2:touch out rectangle , display 4 page
//----------------------------------------------------------
/* FIRST Read State, low 2 bit in effect
== a: screen_x --- axis coordinate, from 0 to 255
== b: screen_y --- axis coordinate, from 0 to 255
*/
/* for(;;){
state = *TOUCH_S & 0x03 ;
screen_x = *TOUCH_X & 0x00FF;
screen_y = *TOUCH_Y & 0x00FF;
sx = screen_x;
sy = screen_y;
DelayMs(100);
if(state == 2){
if((sx>=64 && sx<= 182)&&(sy>=117 && sy<=158)){
ClrScreen(COLOR_GREEN,LCD_ON + DIS_PAGE3 + WR_PAGE3);
Line(148,190,475,190,COLOR_BLACK,lcd_cmd);
Line(148,189,148,285,COLOR_BLACK,lcd_cmd);
Line(148,286,475,286,COLOR_BLACK,lcd_cmd);
Line(476,190,476,285,COLOR_BLACK,lcd_cmd);
Line(171,220,450,220,COLOR_BLACK,lcd_cmd);
Line(171,219,171,255,COLOR_BLACK,lcd_cmd);
Line(171,256,450,256,COLOR_BLACK,lcd_cmd);
Line(451,220,450,256,COLOR_BLACK,lcd_cmd);
}else{
for(;;){
DelayMs(100); Lcd.cmd = LCD_ON + DIS_PAGE0;
DelayMs(100); Lcd.cmd = LCD_ON + DIS_PAGE1;
DelayMs(100); Lcd.cmd = LCD_ON + DIS_PAGE2;
DelayMs(100); Lcd.cmd = LCD_ON + DIS_PAGE3;
state = *TOUCH_S & 0x03 ;
screen_x = *TOUCH_X & 0x00FF;
screen_y = *TOUCH_Y & 0x00FF;
tx = screen_x;
ty = screen_y;
if(state == 2){
if((tx>=64 && tx<= 182)&&(ty>=117 && ty<=158)){
break ;
}
}
}
}
}
}*/
}
//---------------------------------------------------------------------------
// Dot(),Line(),ClrScreen()----basic operate function
//---------------------------------------------------------------------------
// when draw point,input coordinate--(x,y),and color;
// when x or y write into register,add offset;
// draw point;
/*
== unsigned int x,y is coordinate;
== x: x-axis coordinate, from 0 to X_max;
== y: y-axis coordinate, from 0 to Y_max;
== color: set point (x,y) color;
*/
/*void Dot(unsigned int x, unsigned int y, unsigned int color)
{
Lcd.x = X_bias + x;
Lcd.y = Y_bias + y;
Lcd.data = color;
}*/
// draw line -- (beeline , bias);
/*
== a: axis coordinate -- (x0,y0),(x1,y1);
== b: x0,x1--axis coordinate, from 0 to X_max;
== c: y0,y1--axis coordinate, from 0 to Y_max;
== d: col -- set line color;
== e: cmd -- pass parameter;
*/
/*void Line(Uint16 x0, Uint16 y0, Uint16 x1, Uint16 y1, Uint16 col, Uint16 cmd)
{
Uint16 j, tmp;
int dx, dy, n, k, i, x, y, f;
if(y0 == y1)
{
if(x0 >= x1)
{
tmp = x0; x0 = x1; x1 = tmp;
}
Lcd.x = X_bias + x0 - 1;
Lcd.y = Y_bias + y0;
Lcd.cmd = (cmd & 0x00fc) | X_AUTO;
for(j = 0; j <= x1 - x0; j++)
{
Lcd.data = col;
asm(" RPT #35 || NOP ");
}
}
else if(x0 == x1)
{
if(y0 >= y1)
{
tmp = y0;
y0 = y1;
y1 = tmp;
}
Lcd.x = X_bias + x0;
Lcd.y = Y_bias + y0 - 1;
Lcd.cmd = (cmd & 0x00fc) | Y_AUTO;
for(j = 0; j <= y1 - y0; j++)
{
Lcd.data = col;
asm(" RPT #35 || NOP ");
}
}
else
{
if(x0 > x1)
{
tmp = x0; x0 = x1; x1 = tmp;
tmp = y0; y0 = y1; y1 = tmp;
}
dx = x1 - x0;
dy = abs(y1 - y0);
n = dx + dy;
k = y1 >= y0 ? 1 : 4;
x = x0;
y = y0;
for(i = 0, f = 0; i < n; i++)
{
if(f >= 0) {
if(k == 1) {
Dot(x++, y, col); f -= dy;
if(dx == 0) { x--; i--; }
}
else
{ Dot(x, y--, col); f -= dx; }
}else
{
if(k == 1)
{ Dot(x, y++, col); f += dx; }
else
{ Dot(x++, y, col); f += dy; }
}
}
}
}*/
// clear screen
/*
== a: color -- set screen color;
== b: cmd -- pass parameter;
*/
void ClrScreen(Uint16 color,Uint16 cmd)
{
unsigned int x, y;
for(y = 0; y <= Y_max; y++)
{
Lcd.x = X_bias - 1;
Lcd.y = Y_bias + y;
Lcd.cmd = (cmd & 0x00fc) | X_AUTO;
for(x = 0; x <= X_max; x++)
{
Lcd.data = color;
asm(" RPT #32 || NOP ");
}
}
}
void Disp_KindsofPho(Uint16 x, Uint16 y, const unsigned int *p, unsigned int Cmd)
{
Uint16 j, k, cc, cf_num, Aw, Ah, w;
y += Y_bias;
w = *p++; Aw = x + w; Ah = y + *p++;
for(j = y; j < Ah; ) {
if((*p & 0x8000) == 0x8000)
{ cf_num = *p - 0x8000; p++; cc = *p++; }
else
{ cf_num = 1; cc = *p++; }
Lcd.x = x + X_bias - 1;
Lcd.y = y;
Lcd.cmd = (Cmd & 0x7c) | X_AUTO;
for(k = 0; k < cf_num; k++)
{ Lcd.data = cc; asm(" RPT #10 || NOP "); }
x += k;
if(x >= Aw)
{ j++; x -= w; y++; }
}
}
void Disp_word(unsigned int x0, unsigned int y0,unsigned int color,const unsigned int *spr)
{
unsigned int char_byte, high, wide, i, j, p = 0, k, temp, T;
int x = x0, y = y0;
temp = *spr++;
wide = (temp & 0xFF00) >> 8;
high = temp & 0x00FF;
Lcd.cmd = lcd_cmd;
for( k = 0; k < high; k++)
{
for( j = 0; j < wide; j++,p++)
{
if(!k) { T = *spr; }
if((p >> 3) % 2 == 0) { char_byte = (T & 0xFF00) >> 8; }
else { char_byte = T & 0x00FF; T = *(++spr); }
for( i = 0; i < 8; i++)
{
if((char_byte & 0x80) == 0x80) Dot(x, y, color);
char_byte = char_byte << 1; x++;
if(i < 7) { j++; p++; }
}
}
x = x0; y++;
}
}
void Disp_four_word(unsigned int x0,unsigned int y0,unsigned int space,
unsigned int color,const unsigned int *p1,const unsigned int *p2,
const unsigned int *p3,const unsigned int *p4)
{
Disp_word(x0,y0,color,p1);
Disp_word(x0+16+space,y0,color,p2);
Disp_word(x0+32+2*space,y0,color,p3);
Disp_word(x0+48+3*space,y0,color,p4);
}
/*void Disp_key(unsigned int x0,unsigned int y0,unsigned int color,unsigned int cmd)
{
unsigned int i,j,k;
//----- 显示数字小键盘 ------
for(i = 0, k = y0; k <= 33*3+y0; k += 33) // 四行
for(j = x0; j <= 65*2+x0; j += 65) // 三列
{
Text_block(j,k-2,j+45,k+18,color,cmd);// 画数字按钮框
if(i <= 9) //画9-0数字
Disp_word(j+20,k,992,num_pt[i++]);
else if(i++ == 10)// 画确定
{
Disp_word(j+5,k,992,ph54);
Disp_word(j+25,k,992,hz19);
}
else// 画取消
{
Disp_word(j+5,k,992,ph55);
Disp_word(j+25,k,992,ph56);
}
}
}*/
/*void Cha_value(unsigned int x0,unsigned int y0,unsigned int color,
unsigned int cmd) // 画修改参数值组合体
{
Disp_word(x0,y0,color,ph50); // 修改____值
Disp_word(x0+18,y0,color,ph51);
Disp_word(x0+121,y0,color,ph52);
Print_line(x0+40,y0+18,x0+115,y0+18,31744,cmd);
Text_block(x0+32,y0+27,x0+116,y0+47,color,cmd);
Disp_key(x0-13,y0+63,color,cmd);
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -