EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / problem in code of avr keypad coz of which o/p is not coming properly

problem in code of avr keypad coz of which o/p is not coming properly

|

Microcontroller › AVR › problem in code of avr keypad coz of which o/p is not coming properly

  • This topic has 2 replies, 2 voices, and was last updated 12 years, 3 months ago by Ananth.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • April 22, 2013 at 8:59 am #2287
    Ananth
    Participant

     

    //  Keypad Program  
    /*
    LCD DATA port—-PORT A
    ctrl port


    PORT B   //PORT GIVEN TO LCD
    ctrlk port


    PORTD  //PORT GIVEN TO KEYPHONE
    rs


    PB0
    rw


    PB1
    en


    PB2
    */
     
    #include<avr/io.h>
    #include<util/delay.h>
     
    #define LCD_DATA PORTA // LCD data port
    #define ctrl PORTB
    #define ctrlk PORTD
    #define en PB2 // enable signal
    #define rw PB1 // read/write signal
    #define rs PB0 // register select signal
    #define c1 PD0
    #define c2 PD1
    #define c3 PD2
    #define r1 PD3
     
    #define r2 PD4
    #define r3 PD5
    #define r4 PD6
    //unsigned char arr[10]=”Appin Labs”;
     
    void LCD_cmd(unsigned char cmd);
    void init_LCD(void);
    void LCD_write(unsigned char data);
    void col3();
    void col2();
    void col1();
     
    int main()
    {
    //unsigned char arr[10]=’Appin Labs’;
    //int i;
    DDRA=0xff; // making LCD_DATA port as output port
    DDRB=0xFF; // making signal as out put
    DDRD=0XFF;
    init_LCD(); // initialization of LCD
    _delay_ms(50); // delay of 50 milli seconds
    /**
    for(i=0;i<10;i++)
    {
    LCD_write(arr);
    }
    */
    //-=–
    while(1)
    {
    ctrlk|=(1<<c1)||(1<<c2)||(1<<c3);
    ctrlk|=(0<<r1)||(0<<r2)||(0<<r3)||(0<<r4);
    if(bit_is_clear(PIND,c1))
    {
    col1();
    LCD_cmd(0x02);
    }
    else if(bit_is_clear(PIND,c2))
    {
    col2();
    LCD_cmd(0x02);
    }
    else 
    {
    col1();
    LCD_cmd(0x02);
    }
    }
    //—-
    return 0;
    }
     
    void init_LCD(void)
    {
    LCD_cmd(0x38); // initialization of 16X2 LCD in 8bit mode
    //_delay_ms(1);
     
    LCD_cmd(0x01); // clear LCD
    //_delay_ms(1);
     
    LCD_cmd(0x0E); // cursor ON
    //_delay_ms(1);
     
    LCD_cmd(0x06); // cursor ON
    //_delay_ms(1);
     
    LCD_cmd(0x80); // —8 go to first line and –0 is for 0th position
    //_delay_ms(1);
    return;
    }
     
    void LCD_cmd(unsigned char cmd)
    {
    LCD_DATA=cmd;
    ctrl =(0<<rs)|(0<<rw)|(1<<en); // RS and RW as LOW and EN as HIGH
    _delay_ms(1);
    ctrl =(0<<rs)|(0<<rw)|(0<<en); // RS, RW , LOW and EN as LOW
    _delay_ms(50);
    return;
    }
     
    void LCD_write(unsigned char data)
    {
    LCD_DATA= data;
    ctrl = (1<<rs)|(0<<rw)|(1<<en); // RW as LOW and RS, EN as HIGH
    _delay_ms(1);
    ctrl = (1<<rs)|(0<<rw)|(0<<en); // EN and RW as LOW and RS HIGH
    _delay_ms(50); // delay to get things executed
    return ;
    }
     
    void col3()
    {
     
    ctrlk|=(1<<r1)|(1<<r2)||(1<<r3)||(1<<r4);
    ctrlk|=(0<<r1);
    if(bit_is_clear(PIND,c3))
    {
    LCD_write(‘3’);
    }
    ctrlk|(1<<r1);
    //—-
    ctrlk|=(0<<r2);
    if(bit_is_clear(PIND,c3))
    {
    LCD_write(‘6’);
    }
    ctrlk|(1<<r2);
    //—-
    ctrlk|=(0<<r3);
    if(bit_is_clear(PIND,c3))
    {
    LCD_write(‘9’);
    }
    ctrlk|(1<<r3);
    //—-
    ctrlk|=(0<<r4);
    if(bit_is_clear(PIND,c3))
    {
    LCD_write(‘#’);
    }
    ctrlk|(1<<r4);
    //—-
    }
     
    void col2()
    {
    ctrlk|=(1<<r1)|(1<<r2)||(1<<r3)||(1<<r4);
    ctrlk|=(0<<r1);
    if(bit_is_clear(PIND,c2))
    {
    LCD_write(‘2’);
    }
    ctrlk|(1<<r1);
    //—-
    ctrlk|=(0<<r2);
    if(bit_is_clear(PIND,c2))
    {
    LCD_write(‘5’);
    }
    ctrlk|(1<<r2);
    //—-
    ctrlk|=(0<<r3);
    if(bit_is_clear(PIND,c2))
    {
    LCD_write(‘8’);
    }
    ctrlk|(1<<r3);
    //—-
    ctrlk|=(0<<r4);
    if(bit_is_clear(PIND,c2))
    {
    LCD_write(‘0’);
    }
    ctrlk|(1<<r4);
    //—-
    }
     
    void col1()
    {
    ctrlk|=(1<<r1)|(1<<r2)||(1<<r3)||(1<<r4);
    ctrlk|=(0<<r1);
    if(bit_is_clear(PIND,c1))
    {
    LCD_write(‘1’);
    }
    ctrlk|(1<<r1);
    //—-
    ctrlk|=(0<<r2);
    if(bit_is_clear(PIND,c1))
    {
    LCD_write(‘4’);
    }
    ctrlk|(1<<r2);
    //—-
    ctrlk|=(0<<r3);
    if(bit_is_clear(PIND,c1))
    {
    LCD_write(‘7’);
    }
    ctrlk|(1<<r3);
    //—-
    ctrlk|=(0<<r4);
    if(bit_is_clear(PIND,c1))
    {
    LCD_write(‘*’);
    }
    ctrlk|(1<<r4);
    //—-
    }
     
     
    April 22, 2013 at 9:15 am #9558
    AJISH ALFRED
    Participant

    Hi Ananth,

    Tell us exactly what happens at the output, then only we can help you better.

    April 22, 2013 at 11:04 am #9562
    Ananth
    Participant

    Hi Ajish,

     

    “2580” is displayed when on lcd screen

    When any button is pressed that button is not displayed on LCD screen

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Faulty heat air gun (dc motor) - problem to locate fault due to Intermittent fault July 19, 2025
  • Does US electric code allow branching ? July 19, 2025
  • Fun with AI and swordfish basic July 19, 2025
  • Sump pit water alarm - Kicad 9 July 19, 2025
  • turbo jet fan - feedback appreciated. July 19, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise