📄 gpio.c
字号:
/*
DM&P Mity-Mite Demo Program.
Copyright (C) 2002 by DM&P.
Those functions are about GPIO.
*/
#include "gpio.h"
#include <conio.h>
#include <dos.h>
#include <time.h>
/* Use BIOS tick to get delay time */
void Delay(int nTime)
{
clock_t clk = clock() + nTime/55+1;
while(clock()<clk);
}
void Beep2()
{
sound(2500);
delay(100);
sound(3500);
delay(100);
nosound();
}
void Beep3()
{
sound(3000);
Delay(200);
sound(2000);
Delay(200);
sound(3000);
Delay(200);
nosound();
}
/* We use bit 12 of GPIO to lighr LED */
void SetLed(int n)
{
unsigned char c;
/* Unlock config register */
outp(0x22,0x13);
outp(0x23,0xc5);
/* Set GPIO bit 12 output */
outp(0x22,0x4f);
c = inp(0x23);
outp(0x22,0x4f);
outp(0x23,0x10|c);
/* Write output */
outp(0x22,0x4d);
outp(0x23,n?0x00:0x10);
}
int GetKey()
{
unsigned char c;
/* Unlock config register */
outp(0x22,0x13);
outp(0x23,0xc5);
/* Set GPIO 15-13 to input */
outp(0x22,0x4f);
c = inp(0x23) & 0xf0;
outp(0x22,0x4f);
outp(0x23,0x0f|c);
/* Read GPIO 15-8 */
outp(0x22,0x4c);
c = inp(0x23);
/* de-bounce */
if(~c&0xe0)
{
int i;
char x = c;
for(i=0;i<3;i++)
if(inp(0x23)!=x)
x = inp(0x23), i=0;
sound(4000);
delay(55);
nosound();
delay(200);
}
/* Return key code */
if(~c&0x20)
return KEY_LEFT;
if(~c&0x40)
return KEY_RIGHT;
if(~c&0x80)
return KEY_ENTER;
return KEY_NULL;
}
/* Dump buffer and read left/right to scroll LCD */
void DumpBuf(char pp[][DUMP_LINE_SIZE],int nMaxLine)
{
int i;
int nIdx = 0;
int k;
int nEnd;
GrLcd_ClearScreen();
while(1)
{
nEnd = (nIdx+4)>=nMaxLine ? nMaxLine : nIdx+4;
if(nIdx!=nEnd)
GrLcd_ClearScreen();
for(i=nIdx;i<nEnd;i++)
GrLcd_printf(0,8*(i-nIdx),"%s",pp[i]);
while((k=GetKey())==KEY_NULL);
if(k==KEY_ENTER)
break;
if(k==KEY_LEFT)
if(nIdx>=1)
nIdx--;
if(k==KEY_RIGHT)
if((nIdx+4)<nMaxLine)
nIdx++;
}
GrLcd_ClearScreen();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -