“AVR PS/2 软件查询控制程序”的版本间的差异

来自丢石头百科
(目 的: 建立PS/2的SimpleSoft测试程序(软件查询读取PS/2接收到的数据) 目标系统: 基于AVR单片机 应用软件: ICCAVR ...)
 
(文本替换 - 替换“www.waveshare.net”为“{{SERVERNAME}}”)
第3行: 第3行:
  
 
/*********************************************************************
 
/*********************************************************************
 微 雪 电 子   WaveShare   <a class="Blue_2_12px_" href="http://www.waveshare.net/" style="color: rgb(7, 66, 184);">http://www.waveShare.net
+
 微 雪 电 子   WaveShare   <a class="Blue_2_12px_" href="http://{{SERVERNAME}}/" style="color: rgb(7, 66, 184);">http://www.waveShare.net
 
             
 
             
 
目    的:   建立PS/2的SimpleSoft测试程序(软件查询读取PS/2接收到的数据)
 
目    的:   建立PS/2的SimpleSoft测试程序(软件查询读取PS/2接收到的数据)

2019年11月19日 (二) 09:22的版本

<tbody></tbody>

/*********************************************************************  微 雪 电 子   WaveShare   <a class="Blue_2_12px_" href="http://wiki.diustou.com/" style="color: rgb(7, 66, 184);">http://www.waveShare.net               目    的:   建立PS/2的SimpleSoft测试程序(软件查询读取PS/2接收到的数据) 目标系统:   基于AVR单片机                                                  应用软件:   ICCAVR                                                       版    本:   Version 1.0                                                        圆版时间:   2005-06-25 开发人员:   SEE 说    明:   若用于商业用途,请保留此段文字或注明代码来源   深 圳 市 微 雪 电 子 有 限 公 司 保 留 所 有 的 版 权     

                                                                                                                                          • /

/*01010101010101010101010101010101010101010101010101010101010101010101


版本更新记录:


实验内容: 按PC键盘,观察单片机读到的数据,使用PA/PB口的LED做指示。


硬件连接: 将PA/PB口的LED指示灯使用短路帽短接; 将PC键盘插入PS2接口, 使用短路帽短接PB0与PS2.SDA, 使用短路帽短接PB1与PS2.SCK


注意事项:  (1)若有加载库函数,请将光盘根目录下的“库函数”下的“ICC_H”文件夹拷到D盘 (2)请详细阅读“使用必读”及相关资料。


10101010101010101010101010101010101010101010101010101010101010101010*/

  1. include <iom16v.h>
  2. include "D:\ICC_H\CmmICC.H"
  3. include "D:\ICC_H\PS2.H"</iom16v.h>
  4. define PRESS_DATA_DDR DDRA
  5. define PRESS_DATA_PORT PORTA
  6. define SHIFT_DATA_DDR DDRD
  7. define SHIFT_DATA_PORT PORTD
  8. define SET_SDA sbi(PORTB,0)
  9. define CLR_SDA cbi(PORTB,0)
  10. define GET_SDA gbi(PINB,0)
  11. define OUT_SDA sbi(DDRB,0)
  12. define IN_SDA cbi(DDRB,0)
  13. define SET_SCK sbi(PORTB,1)
  14. define CLR_SCK cbi(PORTB,1)
  15. define GET_SCK gbi(PINB,1)
  16. define OUT_SCK sbi(DDRB,1)
  17. define IN_SCK cbi(DDRB,1)
  18. define DELAY() {NOP();NOP();NOP();NOP();}

bool rcvF = 0; //是否收到字符标志 uint8 keyVal; //键值 /*-------------------------------------------------------------------- 函数名称:PS2 函数功能: 注意事项: 提示说明: 输 入: 返 回:


*/

void check(void) { static uint8 rcvBits = 0; //接收次数,中断次数

OUT_SCK; //设置"SCK_DDR"为输出 DELAY(); SET_SCK; //"SCK_PORT"输出"1" DELAY();

IN_SCK; //设置"SCK_DDR"为输入 DELAY(); if(!GET_SCK) { if((rcvBits>0) && (rcvBits<9)) {  keyVal=keyVal>>1; //数据是LSB格式 //IN_SDA; //当有对键盘有属性设置时,注意输入输出切换 //DELAY(); if(GET_SDA)  keyVal=keyVal|0x80;  } rcvBits++; while(!GET_SCK); //等待PS/2CLK拉高

if(rcvBits>10) { rcvBits=0; //接收11次表示接收完一帧数据 rcvF=1; //标识有字符已经输入 } } } /*-------------------------------------------------------------------- 函数名称:PS2 函数功能: 注意事项: 提示说明: 输 入: 返 回:


*/

void keyHandle(uint8 val)  { uint8 i; static bool isUp=0; //按键释放动作标志 static bool shift=0; //shift键按下标志 rcvF = 0;  PRESS_DATA_PORT = val; //状态指示 if(!isUp) { switch(val) { case 0xF0 : // a relase action isUp = 1; break; case 0x12 : // Left shift shift = 1; break; case 0x59 : // Right shift shift = 1; break; default: if(!shift) // If shift not pressed {  /* for(i=0; unshifted[i][0]!=val && unshifted[i][0]; i++)

上述写法较为灵活,但KEIL非UNIXC标准,不能采用该写法

  • /

for(i=0; unshifted[i][0]!=val && i<59; i++)

if(unshifted[i][0] == val) 

//状态指示

}  else // If shift pressed {  /* for(i=0; unshifted[i][0]!=val && unshifted[i][0]; i++)

上述写法较为灵活,但KEIL非UNIXC标准,不能采用该写法

  • /

for(i=0; shifted[i][0]!=val && i<59; i++)

if(shifted[i][0] == val)  SHIFT_DATA_PORT = val;//状态指示 } } } else  { isUp=0;  switch(val) { case 0x12 : // Left SHIFT shift = 0; break; case 0x59 : // Right SHIFT shift = 0; break; } } }  /*-------------------------------------------------------------------- 函数名称:PS2 函数功能: 注意事项: 提示说明: 输 入: 返 回:


*/

void main(void) { PRESS_DATA_DDR = 0XFF; SHIFT_DATA_DDR = 0XFF; IN_SDA; while(1) { check(); if(rcvF) keyHandle(keyVal); }

}