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 / 7 segment with 8051 using interrupt

7 segment with 8051 using interrupt

|

Microcontroller › 8051 › 7 segment with 8051 using interrupt

  • This topic has 1 reply, 2 voices, and was last updated 11 years, 5 months ago by Ashutosh Bhatt.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • February 17, 2014 at 2:43 pm #2870
    Amit Raijade
    Participant

    i want to display set-01 on seven segment display using interrupt

     

    i have attached code for it 

     

    but not working well 

     

    #include <reg51.h>
    #define PORT_SEVEN_SEG  P0
     
    #define blank  0x00
    sbit    dig0            =   P2^1;
    sbit    dig1            =   P2^2;
    sbit    dig2            =   P2^3;
    sbit    dig3            =   P2^4;
    sbit    dig4            =   P2^5;
    sbit    dig5            =   P2^6;
     
    unsigned char data  display_arr[6], bcdval[6], dig_count, l_display_arr[6];
     
    //void pin_status();
    void initialize();
    /*
    void delay(unsigned int ms)  
    { 
     
            int i, j;
            for(i=0;i<ms;i++)
                    for(j=0;j<300;j++);
    }
    */
    void main()
     { 
       int i,j=0;
       code unsigned char Setup1[] = {0x15,0x91,0xD1,0xFD,0x03,0x6F};                //set-1
    initialize();
    EX0 = 1;
     
    for(i = 0; i < 6;i++){
     
    display_arr = Setup1;
    //delay(1);
    }
      EX0 = 0;
    }
     
    void initialize()
    {
    P0 = blank; //segments off
    P2 = 0xfe; //digits off
    //P1 = 0xff;
     
    TMOD  = 0x00; //gate1, c/t1, m1, m0, gate0, c/t0, m1, m0 
    //  0   0 1   0,   0    0     0   1 timer1 8 bit, timer0 16 bit;  
     
    TCON  = 0x11; //timer1 flag, timer1 on, 
    //timer0 flag, timer0 0n, 
    //ext int1 flag, ext int1 edge/low-(1/0), ext int0 flag, ext int0 edge/low-(1/0)
     
    PCON  = 0x00; //smod, res, res, res, 
    //gf1, gf0, pd, idl
     
    SCON  = 0x40; //sm0, sm1, sm2 (mode 01 8 bit var baud),
    //recv_enb ,tb8,rb8,ti,ri 
     
    IE  = 0x82; //enable all, res, enable timer2, enable serial,
    //enable timer1 , enable extint1, enable timer0, enable extint0   
     
    TH1 = 0xfA;   //f4_2400, fd_9600, fa_4800, e8_1200
    TL1 = 0xfA; 
    TH0  = 0x78;
      TL0     = 0x00;
    //TR0 = 1;
    }
     
     
    void timer0() interrupt 1
    { 
    TH0     = 0x78;
      TL0     = 0x00;
    P0      = 0xff;
     
    if(dig_count == 6)
    dig_count = 0;
     
     
      switch(dig_count)
    {
      case 0:  dig0 = 0;
               dig1 = 1; 
               dig2 = 1;          
              dig3 = 1; 
              dig4 = 1; 
              dig5 = 1; 
              break; 
     
    case 1:   dig0 = 1;
              dig1 = 0; 
              dig2 = 1;          
              dig3 = 1; 
              dig4 = 1; 
              dig5 = 1; 
              break; 
     
    case 2:   dig0 = 1;
              dig1 = 1; 
              dig2 = 0;          
              dig3 = 1; 
              dig4 = 1; 
              dig5 = 1; 
              break; 
     
    case 3:  dig0 = 1;
              dig1 = 1; 
              dig2 = 1;          
              dig3 = 0; 
              dig4 = 1; 
              dig5 = 1; 
              break; 
     
    case 4:   dig0 = 1;
              dig1 = 1; 
              dig2 = 1;          
              dig3 = 1; 
              dig4 = 0; 
              dig5 = 1; 
              break; 
     
    case 5:   dig0 = 1;
              dig1 = 1; 
              dig2 = 1;          
              dig3 = 1; 
              dig4 = 1; 
              dig5 = 0; 
             break; 
    }
     
      P0      = display_arr[dig_count];
      TF0 = 0;
    dig_count++;
    }
     
    void int1() interrupt 2 
     
    { }
     
    void timer1() interrupt 3
    { }
     
    void rec()   interrupt 4
    { }
    February 19, 2014 at 4:52 am #11056
    Ashutosh Bhatt
    Participant

    you have not specified which interrupt you want to use

    in your program you are enabling external interrupt 0 but your ISR is for timer 0 interrupt (interrupt 1 keyword is for timer 0 interrupt)

    also you have not enabled globle interrupt

    use IE = 0x81 to enable external interrupt 0

    and IE = 0x82 to enable timer 0 overflow interrupt

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

RSS Recent Posts

  • Pic18f25q10 osccon1 settings swordfish basic July 18, 2025
  • Sump pit water alarm - Kicad 9 July 18, 2025
  • Anyone jumped from Easyeda std to Easyeda pro? July 17, 2025
  • turbo jet fan - feedback appreciated. July 17, 2025
  • More fun with ws2812 this time XC8 and CLC July 17, 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