⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 display.c

📁 source code for a sample alarm control panel system using Freescale MC9S12DP256 . The project was im
💻 C
字号:
//=============================================================================
// File: DISPLAY.C - V1.00
// Rem.: The ACPRD Project Page on the Web -> http://hc12web.de/acprd
//=============================================================================

//-- Includes -----------------------------------------------------------------

#include "datatypes.h"
#include "display.h"

//-- Static Vars --------------------------------------------------------------

UINT16 disp_buf[DISP_SIZE];	// display buffer: MSB=attribute LSB=character
UINT16 cursor;				// linear cursor position (0..DISP_SIZE-1)

//-- Code ---------------------------------------------------------------------

void _putDisp(UINT16 c) {

	if(c & 0xff)	// if char != 0 then write attr+char
		disp_buf[cursor] = c;
	else			// if char == 0 then write attr only
		*((UINT8 *)(disp_buf + cursor)) = c >> 8; 
	}

//-----------------------------------------------------------------------------

void initDisp(void) {

	clearDisp();
	}

//-----------------------------------------------------------------------------

void clearDisp(void) {

	cursor = DISP_SIZE;
	do {
		cursor--;
		_putDisp(0x20);
		} while(cursor);
	}

//-----------------------------------------------------------------------------

void gotoxyDisp(UINT8 x, UINT8 y) {

	if(x >= DISP_MAXX) x = 0;
	if(y >= DISP_MAXY) y = 0;
	cursor = x + y * DISP_MAXX;
	}

//-----------------------------------------------------------------------------

UINT16 getDispCursor(void) {

	return cursor;
	}

//-----------------------------------------------------------------------------

void setDispCursor(UINT16 cur) {

	cursor = cur;
	}

//-----------------------------------------------------------------------------

void putcDisp(UINT16 c) {

	switch(c & 0xff) {
		case 0x01:	// Cursor right
			cursor++;
			if(cursor >= DISP_SIZE) cursor = 0;
			break;
		case 0x02:	// Cursor down
			cursor += DISP_MAXX;
			if(cursor >= DISP_SIZE) cursor -= DISP_SIZE;
			break;
		case 0x03:	// Cursor left
			if(cursor == 0) cursor = DISP_SIZE;
			cursor--;
			break;
		case 0x04:	// Cursor up
			if(cursor < DISP_MAXX) cursor += DISP_SIZE;
			cursor -= DISP_MAXX;
			break;
		case 0x08:	// BS
			if(cursor == 0) cursor = DISP_SIZE;
			cursor--;
			_putDisp((c & 0xff00) | 0x20);
			break;
		case 0x0a:	// LF+CR
			cursor += DISP_MAXX;
			if(cursor >= DISP_SIZE) cursor -= DISP_SIZE;
		case 0x0d: // CR
			cursor = (cursor / DISP_MAXX) * DISP_MAXX;
			break;
		case 0x0f:	// Cursor down, left
			cursor += DISP_MAXX - 1;
			if(cursor >= DISP_SIZE) cursor -= DISP_SIZE;
			break;
		default:
			_putDisp(c);
			cursor++;
			if(cursor >= DISP_SIZE) cursor = 0;
			break;
		}
	}

//-----------------------------------------------------------------------------

void prDispStr(const UINT8 *s) {

	while(*s) {
		putcDisp(*s);
		s++;
		}
	}

//-----------------------------------------------------------------------------

void prDispSpace(void) {

	putcDisp(' ');
	}

//-----------------------------------------------------------------------------

void prDispMult(UINT16 count, UINT16 c) {

	do {
		putcDisp(c);
		} while(--count);
	}

//-----------------------------------------------------------------------------

void prDisp01d(UINT16 d) {

	if(d > 9) d = '@' - '0'; 
	putcDisp(d + '0');
	}

//-----------------------------------------------------------------------------

void prDisp02d(UINT16 d) {

	if(d <= 99) {
		prDisp01d(d / 10);
		prDisp01d(d % 10);
		}
	else {
		putcDisp('@');
		putcDisp('@');
		}
	}

//-----------------------------------------------------------------------------

void prDisp04d(UINT16 d) {

	if(d <= 9999) {
		prDisp02d(d / 100);
		prDisp02d(d % 100);
		}
	else {
		prDispStr("@@@@");
		}
	}

//=============================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -