AVR PS/2 Software Query Control Program

Publisher:幸福之舞Latest update time:2020-06-27 Source: eefocusKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/************************************************************************         

Purpose: To establish a SimpleSoft test program for PS/2 (software query and read data received by PS/2)

Target system: Based on AVR microcontroller                                                 

Application software: ICCAVR                                                      

Version: Version 1.0                                                       

*************************************************************************/


/*01010101010101010101010101010101010101010101010101010101010101010101

----------------------------------------------------------------------

Version update record:


----------------------------------------------------------------------

Experimental content:

Press the PC keyboard, observe the data read by the microcontroller, and use the LED of the PA/PB port for indication.

----------------------------------------------------------------------

Hardware Connection:

Use a short-circuit cap to short-circuit the LED indicator lights of the PA/PB ports;

Plug the PC keyboard into the PS2 port.

Use a shorting cap to short PB0 and PS2.SDA.

Use a shorting cap to short PB1 and PS2.SCK

----------------------------------------------------------------------

Precautions: 

(1) If you have loaded a library function, please copy the "ICC_H" folder under the "library function" in the root directory of the CD to the D drive.

(2) Please read the “Must-Read” and related materials carefully.

----------------------------------------------------------------------

10101010101010101010101010101010101010101010101010101010101010101010101010101010*/


#include

#include "D:ICC_HCmmICC.H"

#include "D:ICC_HPS2.H"


#define PRESS_DATA_DDR DDRA

#define PRESS_DATA_PORT PORTA

#define SHIFT_DATA_DDR DDRD

#define SHIFT_DATA_PORT PORTD


#define SET_SDA sbi(PORTB,0)

#define CLR_SDA cbi(PORTB,0)

#define GET_SDA gbi(PINB,0)

#define OUT_SDA sbi(DDRB,0)

#define IN_SDA cbi(DDRB,0)


#define SET_SCK sbi(PORTB,1)

#define CLR_SCK cbi(PORTB,1)

#define GET_SCK gbi(PINB,1)

#define OUT_SCK sbi(DDRB,1)

#define IN_SCK cbi(DDRB,1)


#define DELAY() {NOP();NOP();NOP();NOP();}


bool rcvF = 0; //Whether the character flag is received

uint8 keyVal; //key value


/*--------------------------------------------------------------------

Function name: PS2

Function:

Precautions:

Tips:

enter:

return:

--------------------------------------------------------------------*/

void check(void)

{

static uint8 rcvBits = 0; //Number of receptions, number of interruptions


OUT_SCK; //Set "SCK_DDR" to output

DELAY();

SET_SCK; //"SCK_PORT" outputs "1"

DELAY();


IN_SCK; //Set "SCK_DDR" as input

DELAY();

if(!GET_SCK)

{

if((rcvBits>0) && (rcvBits<9))

keyVal=keyVal>>1; //Data is in LSB format

//IN_SDA; //When there are attribute settings for the keyboard, pay attention to input and output switching

//DELAY();

if(GET_SDA) 

keyVal=keyVal|0x80; 

}

rcvBits++;

while(!GET_SCK); //Wait for PS/2CLK to be pulled high


if(rcvBits>10)

{

rcvBits=0; //Receiving 11 times means receiving a frame of data

rcvF=1; //Indicates that a character has been entered

}

}

}

/*--------------------------------------------------------------------

Function name: PS2

Function:

Precautions:

Tips:

enter:

return:

--------------------------------------------------------------------*/

void keyHandle(uint8 val) 

{

uint8 i;

static bool isUp=0; //Button release action flag

static bool shift=0; //Shift key pressed flag

rcvF = 0; 

PRESS_DATA_PORT = val; //status indication

if(!isUp)

{

switch(val)

{

case 0xF0 : // a release 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++)

;

The above writing method is more flexible, but KEIL is not a UNIXC standard and cannot be used.

*/

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

;

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

; //Status indication


else // If shift pressed

/*

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

;

The above writing method is more flexible, but KEIL is not a UNIXC standard and cannot be used.

*/

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

;

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

SHIFT_DATA_PORT = val; //status indication

}

}

}

else 

{

isUp=0; 

switch(val)

{

case 0x12 : // Left SHIFT

shift = 0;

break;

case 0x59 : // Right SHIFT

shift = 0;

break;

}

}

/*--------------------------------------------------------------------

Function name: PS2

Function:

Precautions:

Tips:

enter:

return:

--------------------------------------------------------------------*/

void main(void)

{

PRESS_DATA_DDR = 0XFF;

SHIFT_DATA_DDR = 0XFF;

IN_SDA;

while(1)

{

check();

if(rcvF)

keyHandle(keyVal);

}

}


Keywords:AVR Reference address:AVR PS/2 Software Query Control Program

Previous article:AVR PS/2 Hardware Interrupt Control Program
Next article:PS/2 Subroutines

Recommended ReadingLatest update time:2024-11-16 11:48

iWave Systems Launches New V2X Connectivity Hub and Telematics Gateway
According to foreign media reports, based on NXP's latest i.MX 8XLite application processor, design company iWave Systems has built a hybrid V2X Connectivity Hub that can be used as a rugged telematics gateway. The V2X center is designed to enable connections between smart cities and connected mobile travel. By inte
[Automotive Electronics]
iWave Systems Launches New V2X Connectivity Hub and Telematics Gateway
ams and OSRAM join forces with Teknique to accelerate deployment of advanced 2D/3D sensing and imaging systems
ams and OSRAM join forces with Teknique to accelerate deployment of advanced 2D/3D sensing and imaging systems • ams OSRAM and Teknique demonstrated complete 2D/3D vision system solutions; • The system is based on an Ambarella SoC, integrating ams Osram’s Seres camera board and Tekniq
[sensor]
ams and OSRAM join forces with Teknique to accelerate deployment of advanced 2D/3D sensing and imaging systems
S3C6410 Embedded Application Platform Construction (VI) - Linux-3.14.4 Ported to OK6410 (Yaffs2 File System Ported)
I personally think that using the Yaffs2 file system on nandflash is a good solution, but the latest Linux does not support the Yaffs2 file system, and you need to patch the kernel yourself. However, as mentioned earlier, due to differences and compatibility issues between kernels, various compilation problems will
[Microcontroller]
S3C6410 Embedded Application Platform Construction (VI) - Linux-3.14.4 Ported to OK6410 (Yaffs2 File System Ported)
AVR Development Arduino Method (V) Analog-to-Digital Conversion Subsystem
The analog-to-digital conversion subsystem is used to convert the analog signal collected by the sensor into a digital signal. The analog-to-digital conversion subsystem of the Arduino UNO R3 main processor ATMega328P uses a successive approximation method to complete the analog-to-digital conversion. It is very sim
[Microcontroller]
Solution to the defect of Siemens PR2 type disconnector not closing properly
introduction As the main equipment of substation, disconnectors play an indispensable role in ensuring the reliable operation of substations. When disconnectors cannot open and close normally or the opening and closing is not in place, it will seriously affect the safety and stability of the power grid, especia
[Embedded]
Solution to the defect of Siemens PR2 type disconnector not closing properly
Samsung Galaxy Fold 2 goes into mass production: Equipped with UTG technology, cheaper
      On May 28, foreign media sammobile quoted Korean insiders as saying that Samsung has placed a production order for Galaxy Fold 2 in recent days, which includes ultra-thin glass (UTG) technology.   This also means that the Galaxy Fold 2 becomes Samsung's second device equipped with UTG technology after the Gala
[Mobile phone portable]
AVR446_Linear speed control of stepper motor Stepper motor curve analysis
                      1.1. MCU code processing // Define the timer pre-scaling, the actual clock frequency of the timer is: 72MHz/(STEPMOTOR_TIMx_PRESCALER+1) #define STEPMOTOR_TIM_PRESCALER 3 // Stepper motor driver subdivision setting: 32 // Define the timer period, set the output comparison mode
[Microcontroller]
AVR446_Linear speed control of stepper motor Stepper motor curve analysis
Analysis on the Principle and Application of Vehicle-to-Everything (V2X) Communication Technology
According to the definition of the Internet of Vehicles Industry Technology Innovation Alliance, the Internet of Vehicles is a large system network consisting of in-vehicle network, inter-vehicle network and vehicle-cloud network for radio communication and information exchange. As shown in Figure 1, through the int
[Embedded]
Analysis on the Principle and Application of Vehicle-to-Everything (V2X) Communication Technology
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号