基于单片机的液体点滴控制系统设计说明书论文

发布时间 : 星期日 文章基于单片机的液体点滴控制系统设计说明书论文更新完毕开始阅读

南京工程学院毕业设计说明书(论文)

KeyDelay1ms(10); ucKeyValue = ScanKey();

if (ucKeyValue == 0){s_ucFastKey = 0; return 0;} #if BELL_ENABLE == 1 BELL_ON();

KeyDelay1ms(10); BELL_OFF(); #endif

if (type == 0) {

s_ucFastKey = ucKeyValue; while (s_ucFastKey != 0) {

s_ucFastKey = ScanKey(); ucKeyValue |= s_ucFastKey; }

s_ucFastKey = 0; return ucKeyValue; } else {

uint16 uiDelay = 0;

if (ucKeyValue != s_ucFastKey){s_ucFastKey = 0;}

if (s_ucFastKey == 0) {

uiDelay = 0;

while (ScanKey() != 0) {

ucKeyValue |= ScanKey(); KeyDelay1ms(1); uiDelay++;

if (uiDelay > FAST_KEY_DELAY){s_ucFastKey = ucKeyValue;}戧礱風熗浇鄖适泞嚀贗。 } }

else //fast==1 {

uiDelay = 0;

while (ScanKey() != 0) {

KeyDelay1ms(1);

32

ucKeyValue; return 南京工程学院毕业设计说明书(论文)

uiDelay++;

if (uiDelay > FAST_KEY_RATE){return ucKeyValue;} } } }

return ucKeyValue; }

5.5 显示程序

要把液体点滴的速度和累计滴数以及报警开关的状态显示在LCD液晶显

示屏上,当超过异常时间没有液体流过(假定初始异常间隔为10s)则产生报警,其中涉及一些计算速度的公式为:1/中断时间=速度。显示流程图如图5-4所示:購櫛頁詩燦戶踐澜襯鳳。

图5-4显示流程图

显示代码如下: ①读取LCD数据代码如下:

uint8 LcdRead(uint8 x, uint8 y) {

if (y > 1){return 0;} if (x > 15){return 0;}

33

南京工程学院毕业设计说明书(论文)

if (y == 0) {

Lcd_CheckBusy();

WriteComPort(LCD_SET_DDRAM_ADDR | x); } else {

Lcd_CheckBusy();

WriteComPort(LCD_SET_DDRAM_ADDR | 0x40+x); }

Lcd_CheckBusy();

return ReadDataPort();

②写LCD数据代码如下:

void LcdWrite(uint8 x, uint8 y, uint8 ucData) {

if (y > 1){return;} if (x > 15){return;}

if (y == 0) {

Lcd_CheckBusy();

WriteComPort(LCD_SET_DDRAM_ADDR | x); } else {

Lcd_CheckBusy();

WriteComPort(LCD_SET_DDRAM_ADDR | 0x40+x); }

Lcd_CheckBusy();

WriteDataPort(ucData); uiLcd_x = x+1; uiLcd_y = y; return; }

③从(x,y)的右下方显示字符串,x点后移,代码如下:

void DrawText(uint8 x, uint8 y, uint8 *pucStr) {

GotoXY(x, y);

while(0 != *pucStr) {

LcdWrite(GetX(), GetY(), *pucStr);

34

南京工程学院毕业设计说明书(论文)

pucStr++; } return; }

④LCD清屏代码如下:

void LcdClear(void) {

Lcd_CheckBusy();

WriteComPort(LCD_CLEAR_DISPLAY); uiLcd_x = 0; uiLcd_y = 0; return; }

5.6 延时子程序

延时子程序的作用是是显示屏在初始化的时候延迟一段时间,防止显示屏

初始化出现错误。在按键部分也能起到去抖动的作用,如果按键部分不去抖动,会导致连续按下好几次的负面效果,因此按键部分必须采用延时去抖动。延时程序的代码如下所示:嗫奐闃頜瑷踯谫瓒兽粪。 void SoftDelay(uint16 ms) {

while (ms != 0) {

SoftDelay_1ms(); ms--; } }

void SoftDelay_1ms(void) {

uint16 data i;

for (i=110; i!=0; i--){;} }

35

联系合同范文客服:xxxxx#qq.com(#替换为@)