-
Ordering information
Call us or mail us for inquiries & availability: info@mtronixtech.com
-
Search projects by Price
-
Project Categories
- Robots and Robotics
- GSM based Projects
- GPS based Projects
- RFID based Projects
- Energy Saving
- Wireless Communication
- DTMF based projects
- SMS based projects
- RF Remote
- Mobile Controlled
- Power Saver
- Sensor based Projects
- Alcohol Sensor
- heartbeat Sensor
- Humidity Sensor
- Infrared Sensor
- Level Sensor
- Light Sensor
- LPG Gas Sensor
- Moisture Sensor
- Temperature Sensor
- Vibration Sensor
- Weight Sensor
-
Search projects by Application
Project Videos:
Landrover Robot Operated by Cellphone
Industrial Automation using Cellphone
Password based door locking
Automatic room light controller
Temperature controlled fan
Electronic voting machine
Search by Components
89c51 89s51 89s52 89v51RD2 555 ADC0808 ADC0809 AT24c16 AT24c64 AT89s52 Battery BC547 Bulb Buzzer Darlington Pair DC motor Decoder EEPROM Fan GPS GSM IR LED Keypad L239D LCD Display LDR LED LM35 LM358 Matrix keypad MAX232 Motor Driver MQ6 PC Interface Relay RFID Card RFID Reader RFID Tags Sim300 sim900 SR86 SR87 Stepper Motor SYHS220 TSOP1738
Home
Simple Keypad
Embedded C code for Simple Keypad
Sample code for Simple Keypad.
Following code can be using for AVR series ICs like: ATmega8, ATmega16, ATmega32.
#include <avr/io.h> #include <util/delay.h> #ifndef cbi #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #endif #ifndef sbi #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #endif void initports(void); int main(void) { initports(); while(1) { if(bit_is_clear(PINA,0)) { _delay_ms(5); // debounce delay if(bit_is_clear(PINA,0)) { cbi(PORTB,0); sbi(PORTB,1); sbi(PORTB,2); } else { } } else { } if(bit_is_clear(PINA,1)) { _delay_ms(5); if(bit_is_clear(PINA,1)) { sbi(PORTB,0); cbi(PORTB,1); sbi(PORTB,2); } else { } } else { } if(bit_is_clear(PINA,2)) { _delay_ms(5); if(bit_is_clear(PINA,2)) { sbi(PORTB,0); sbi(PORTB,1); cbi(PORTB,2); } else { } } else { } } return 0; } void initports(void) { cbi(DDRA,0); //set A.0 as input cbi(DDRA,1); //set A.1 as input cbi(DDRA,2); //set A.2 as input sbi(DDRB,0); //set B.0 as output sbi(DDRB,1); //set B.1 as output sbi(DDRB,2); //set B.2 as output PORTB = 0xFF; //turn off all LEDs return; }