📄 cfg.c
字号:
/*
*********************************************************************************************************
* Embedded Systems Building Blocks
* Complete and Ready-to-Use Modules in C
*
* Configuration File
*
* (c) Copyright 1999, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* Filename : CFG.C
* Programmer : Jean J. Labrosse
*********************************************************************************************************
*/
#include "includes.h"
static INT16S AITestCnts;
/*$PAGE*/
/*
*********************************************************************************************************
* KEYBOARD
* INITIALIZE I/O PORTS
*********************************************************************************************************
*/
#if MODULE_KEY_MN
void KeyInitPort (void)
{
outp(KEY_PORT_CW, 0x82); /* Initialize 82C55A: A=OUT, B=IN (COLS), C=OUT (ROWS) */
}
/*
*********************************************************************************************************
* KEYBOARD
* SELECT A ROW
*
* Description : This function is called to select a row on the keyboard.
* Arguments : 'row' is the row number (0..7) or KEY_ALL_ROWS
* Returns : none
* Note : The row is selected by writing a LOW.
*********************************************************************************************************
*/
void KeySelRow (INT8U row)
{
if (row == KEY_ALL_ROWS) {
outp(KEY_PORT_ROW, 0x00); /* Force all rows LOW */
} else {
outp(KEY_PORT_ROW, ~(1 << row)); /* Force desired row LOW */
}
}
/*
*********************************************************************************************************
* KEYBOARD
* READ COLUMNS
*
* Description : This function is called to read the column port.
* Arguments : none
* Returns : the complement of the column port thus, ones are keys pressed
*********************************************************************************************************
*/
INT8U KeyGetCol (void)
{
return (~inp(KEY_PORT_COL)); /* Complement columns (ones indicate key is pressed) */
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* MULTIPLEXED LED DISPLAY
* I/O PORTS INITIALIZATION
*
* Description: This is called by DispInit() to initialize the output ports used in the LED multiplexing.
* Arguments : none
* Returns : none
* Notes : 74HC573 8 bit latches are used for both the segments and digits outputs.
*********************************************************************************************************
*/
#if MODULE_LED
void DispInitPort (void)
{
outp(DISP_PORT_SEG, 0x00); /* Turn OFF segments */
outp(DISP_PORT_DIG, 0x00); /* Turn OFF digits */
}
/*
*********************************************************************************************************
* MULTIPLEXED LED DISPLAY
* SEGMENTS output
*
* Description: This function outputs seven-segment patterns.
* Arguments : seg is the seven-segment patterns to output
* Returns : none
*********************************************************************************************************
*/
void DispOutSeg (INT8U seg)
{
outp(DISP_PORT_SEG, seg);
}
/*
*********************************************************************************************************
* MULTIPLEXED LED DISPLAY
* DIGIT output
*
* Description: This function outputs the digit selector.
* Arguments : msk is the mask used to select the current digit.
* Returns : none
*********************************************************************************************************
*/
void DispOutDig (INT8U msk)
{
outp(DISP_PORT_DIG, msk);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* LCD DISPLAY MODULE
* INITIALIZE DISPLAY DRIVER I/O PORTS
*
* Description : This initializes the I/O ports used by the display driver.
* Arguments : none
* Returns : none
*********************************************************************************************************
*/
#if MODULE_LCD
void DispInitPort (void)
{
outp(DISP_PORT_CMD, 0x82); /* Set to Mode 0: A are output, B are inputs, C are outputs */
}
/*
*********************************************************************************************************
* LCD DISPLAY MODULE
* WRITE DATA TO DISPLAY DEVICE
*
* Description : This function sends a single BYTE to the display device.
* Arguments : 'data' is the BYTE to send to the display device
* Returns : none
* Notes : You will need to adjust the value of DISP_DLY_CNTS (LCD.H) to produce a delay between
* writes of at least 40 uS. The display I used for the test actually required a delay of
* 80 uS! If characters seem to appear randomly on the screen, you might want to increase
* the value of DISP_DLY_CNTS.
*********************************************************************************************************
*/
void DispDataWr (INT8U data)
{
INT8U dly;
outp(DISP_PORT_DATA, data); /* Write data to display module */
outp(DISP_PORT_CMD, 0x01); /* Set E line HIGH */
DispDummy(); /* Delay about 1 uS */
outp(DISP_PORT_CMD, 0x00); /* Set E line LOW */
for (dly = DISP_DLY_CNTS; dly > 0; dly--) { /* Delay for at least 40 uS */
DispDummy();
}
}
/*
*********************************************************************************************************
* LCD DISPLAY MODULE
* SELECT COMMAND OR DATA REGISTER
*
* Description : This function read a BYTE from the display device.
* Arguments : none
*********************************************************************************************************
*/
void DispSel (INT8U sel)
{
if (sel == DISP_SEL_CMD_REG) {
outp(DISP_PORT_CMD, 0x02); /* Select the command register (RS low) */
} else {
outp(DISP_PORT_CMD, 0x03); /* Select the data register (RS high) */
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -