Menu

2 display 7seg

Help
2009-01-29
2013-05-30
  • pierinodalatina piero

    my code
    #chip 18f452, 8
    #config osc=hs, wdt=off, bor=off, lvp=off

    #define displaycount 2
    #define displayporta portd
    #define displayportb portd
    #define dispselectA set portb.4 on set portb.5 off
    #define dispselectB set portb.4 off set portb.5 on
    dir b out
    dir d out

    for cont = 1 to 9
    displayvalue 1, cont
    wait 1 sec
    next cont
    for cont1 = 0 to 9 step 2
    displayvalue 2, cont1
    wait 1 sec
    next cont1

    sorry for my english
    well the first for-next work
    but the second for-next show
    both the display.
    any idea
    tanks piero

     
    • Nobody/Anonymous

      work very well with 4 7segmentdisplay (based on a response in a recent post)

      '=================================================
      'Chip model
      #chip 16F628A, 4
      #config OSC = INTOSC_OSC_NOCLKOUT, WDT = OFF
      'config OSC = XT, WDT = OFF

      #define StartUpDelay 100 ms

      'setting the 7 segment display with 2 displays
      #define displaycount 4

      #define DispSelectA nop 
      #define DispSelectB nop
      #define DispSelectC nop
      #define DispSelectD nop

      #define Display1 PortA.0
      #define Display2 PortA.1
      #define Display3 PortA.2
      #define Display4 PortA.3
      #define waitDisplay wait 6 ms

      #define DisplayPortA PORTB
      #define DisplayPortB PORTB
      #define DisplayPortC PORTB
      #define DisplayPortD PORTB

      dir PORTB.0 out
      dir PORTB.1 out
      dir PORTB.2 out
      dir PORTB.3 out
      dir PORTB.4 out
      dir PORTB.5 out
      dir PORTB.6 out
      dir PORTB.7 out

      dir PORTA.0 out
      dir PORTA.1 out
      dir PORTA.2 out
      dir PORTA.3 out
      dir PORTA.4 in

      DataCount = 0

      Startup:
      Wait StartUpDelay

      Seg = 0
      Main:
          dataCount = 0
          dataCount = seg
          Centenas = dataCount/100
          Dezenas = (dataCount %100)/10
          Unidades = dataCount % 10
          timer0=0
          for icounter = 1 to 10
                Set Display2 ON:Set Display3 ON:Set Display4 ON:Set Display1 OFF
                displayvalue 1, Unidades
                waitDisplay
                Set Display1 ON:Set Display3 ON:Set Display4 ON:Set Display2 OFF
                displayvalue 2, Dezenas
                waitDisplay
                Set Display1 ON:Set Display2 ON:Set Display4 ON:Set Display3 OFF
                displayvalue 3, Centenas
                waitDisplay
                Set Display1 ON:Set Display2 ON:Set Display3 ON:Set Display4 OFF
                displayvalue 4, 0
                waitDisplay
          next
      seg ++
      iCounter = 1
      wait 200 ms
      Goto Main
      '================================================

       
    • mmotte

      mmotte - 2009-03-28

      Even 6 Leds  work but I was not impressed with the brightness

      Some numbers are brighter than others

      Maybe the transistors need to be matched?

      Mike

      'LED display with 6 multiplex LEDs
      ' T1 osc clock interrupt 1 sec
      '1/2008  Mike Otte

      #chip 16F886, 8
      #config OSC = INTRC_IO

      '  Variables

      #define DisplayCount 6

      #define DisplayPortA PORTB
      #define DisplayPortB PORTB
      #define DisplayPortC PORTB
      #define DisplayPortD PORTB
      #define DisplayPortE PORTB
      #define DisplayPortF PORTB

      #define DispSelectA Set PORTA.0 off: Set PORTA.1 on: Set PORTA.2 on: Set PORTA.3 on: Set PORTA.4 on: Set PORTA.5 on
      #define DispSelectB Set PORTA.0 on: Set PORTA.1 off: Set PORTA.2 on: Set PORTA.3 on: Set PORTA.4 on: Set PORTA.5 on
      #define DispSelectC Set PORTA.0 on: Set PORTA.1 on: Set PORTA.2 off: Set PORTA.3 on: Set PORTA.4 on: Set PORTA.5 on
      #define DispSelectD Set PORTA.0 on: Set PORTA.1 on: Set PORTA.2 on: Set PORTA.3 off: Set PORTA.4 on: Set PORTA.5 on
      #define DispSelectE Set PORTA.0 on: Set PORTA.1 on: Set PORTA.2 on: Set PORTA.3 on: Set PORTA.4 off: Set PORTA.5 on
      #define DispSelectF Set PORTA.0 on: Set PORTA.1 on: Set PORTA.2 on: Set PORTA.3 on: Set PORTA.4 on: Set PORTA.5 off
       
      'The last block of constants connects the first 4 pins on PORTA to either ground (off) or Vdd (on). Each constant is a macro which is called when the matching display is about to be written to. It needs to connect all of the cathodes to Vdd, except for the one that is to be used which must be connected to ground.

      'Make sure that you call the DisplayValue and/or DisplayChar routines very frequently! GCBASIC doesn't do this automatically. 

      #define inchrs PORTC.3
      #define incmin PORTC.4
      #define incsec PORTC.2

      RTCinit

      'Pin Direction
      DIR PORTA OUT
      DIR PORTB OUT
      dir inchrs in
      dir incmin in
      dir incsec in

      hours =0
      mins =0      
      secs = 5

      dim Message(10)
      Message() = "Hello "

      Mainloop:
      sayhello
      secs =0
      mins =0
      hours =0

      timeloop:
      secs = secs +1 ' Increment seconds
      if  secs < 60 then goto fins  ' yes, done
      secs = 0  'Clear seconds
      mloop:
      mins = mins+1  ' Increment minutes
      if  mins < 60 then goto fins  ' yes, done
      mins = 0   ' clear minutes
      hloop:
      hours = hours +1 ' Increment hours
      if  hours < 24 then goto fins  ' yes, done
      hours =0 ' Clear hours

      fins:
          'hour disp
          tens=hours/10
          DisplayValue 6,tens
          ones=hours-tens*10
          Wait 8 ms
          DisplayValue 5,ones
           Wait 8 ms  
          'min disp
          tens=mins/10
          DisplayValue 4,tens
          ones=mins-tens*10
          Wait 8 ms
          DisplayValue 3,ones
          Wait 8 ms
          'sec disp
          tens=secs/10
          DisplayValue 2,tens
          Wait 8 ms
          ones=secs-tens*10
          DisplayValue 1,ones
              
           
            'AdjustTime
            Wait 8 ms
            if  (inchrs =0) AND (incsec = 1)  then goto hloop
            if  (incmin =0) AND (incsec = 1) then goto mloop

      goto fins

      Goto Mainloop

      ' ----------------- Subroutines below --------------------------
      sub  sayhello
      hello:
        for DispMessage = 1 to 6
         DisplayChar 7-DispMessage, Message(DispMessage)
         wait 25 10ms
        next
      'goto hello
      end sub

      sub RTCinit
      'BANKSEL TMR1H
      MOVLW 0x80 ; Preload TMR1 register pair
      MOVWF TMR1H ; for 1 second overflow
      CLRF TMR1L
      BSF     INTCON, PEIE    ; Enable Peripheral Interrupts
      'BSF     INTCON, RBIE    ; Disable PORTB<7:4> Change Interrupts
      BSF     INTCON, GIE     ; Enable all Interrupts
      MOVLW b'00001111' ; Configure for external clock,
      MOVWF T1CON ; Asynchronous operation, external oscillator
      CLRF secs ; Initialize timekeeping registers local time
      CLRF mins
      CLRF hours

      Wait 5 10us
      'BANKSEL PIE1
      BSF PIE1, TMR1IE ; Enable Timer1 interrupt
      end sub

      sub INTERRUPT
      'BANKSEL TMR1H
      BSF TMR1H, 7 ; Preload for 1 sec overflow
      BCF PIR1, TMR1IF ; Clear interrupt flag
      BSF     INTCON, PEIE    ; Enable Peripheral Interrupts
      'BSF     INTCON, RBIE    ; Disable PORTB<7:4> Change Interrupts
      BSF     INTCON, GIE     ; Enable all Interrupts

      secs += 1 ' Increment seconds
      if  secs < 60 then goto fini  ' yes, done
      secs = 0  'Clear seconds
      mins += 1  ' Increment minutes
      if  mins < 60 then goto fini  ' yes, done
      mins = 0   ' clear minutes
      hours += 1 ' Increment hours
      if  hours < 24 then goto fini  ' yes, done
      hours =0 ' Clear hours
      fini:  'Done

      end sub

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.