Seven segment display 4 digit for shift 595 For Basic PRO Compiler




@ device pic16f877
define osc 4
define adc_bits 8
Include "MODEDEFS.bas"  
DEFINE ADC_SAMPLEUS 100 
DEFINE SHIFT_PAUSEUS 100 
ADCON1 = 7          
TRISA =$ff
trisb =$00

 '=======output======='
 dat      vAR portb.0   
 clk      vAR portb.1   
 latch    vAR portb.2 
 relay    VAR portb.3

 '======input========='
  enter   vAR porta.0   
  chg     VAR porta.1

hour    var     byte          
minute  var     byte     
second  var     byte     
prsc1   var     byte       
i       var     byte 
num     var     word
num2    var    word
num3    var    word
digit   var     byte
unit    var     byte
ten     var     byte
roy     var     byte
phun    var     byte
flg_int var     bit   
disp    var     byte
num1    var     byte 
ref     var     byte
hour   = 0  
minute = 0
second = 0
prsc1  = 0
disp   = 0
num    = 0
ref    = 0
num1 = 0
high relay
Pause 500 

start:
     OPTION_REG = 0 	 
     INTCON     = 0      
if chg = 0 then start
start1:     
    gosub set_time
    gosub display
     high relay
     num1 = ref      
     OPTION_REG = 0 	 
     INTCON     = 0
     disable        
  if chg = 1 then start1    
  loop:    
      gosub int_off 
     if enter = 1  then loop                    
      OPTION_REG = $d5	 
      INTCON     = $a0
      pause 50         
      On Interrupt Goto int_on	     
main: 

Goto main    

Disable           
int_on:         
  prsc1 = prsc1 + 1       
     If prsc1 < 61 Then reset_tm0 
           prsc1  = 0
           second = second + 1          
        If second >= 60 Then
           second = 0
           minute = minute + 1
            If minute  >= 100 Then
               minute  = 0
               hour    = hour + 1
               If hour >= 24 Then
                  hour = 0
               Endif
            Endif

         gosub display  
         Endif              
         num2 = ((num1-1)*100)+59 
         num3 = (minute*100)+second                               
         num  = num2-num3
  gosub time_work 
 gosub display
return

int_off:
   OPTION_REG = 0 	 
   INTCON     = 0    
   high relay
   minute = 0
   second = 0
   num1 = ref
   num = 11
   gosub display1
   disable 
return

time_work:
if minute >= num1 then
         OPTION_REG = 0
         INTCON = $00
         second  = 0
         minute  = 0
         num = 0
         high  relay
         gosub display                  
         resume start
         pause 100
       else 
         low   relay 
         gosub display
         pause 5  
      endif
return

reset_tm0:
  if chg = 0 then 
     OPTION_REG = $00
     INTCON = $00
     INTCON.2 = 1
     num2 = 0
     num3 = 0
     num = num2 - num3 
     ref = 0
     num1 = ref
     pause 50   
     resume start   
   else
   INTCON.2 = 0     
  endif      
 Resume  
end 

set_time:  
      if chg = 1 and enter = 0  then               
               pause 150                 
              if ref  >= 100 then
                 ref  = 0
                 num = ref
                 gosub display
                 pause 100                                          
               else   
                 ref  = ref  + 1 
                  num = ref
                  gosub display                 
                 pause 100                                            
               endif                              
        endif 
return
display:  
 digit = num dig 0 
 lookup digit,[$c0,$f9,$a4,$b0,$99,$92,$82,$f8,$80,$90],unit
 PAUSEUS 5
 digit = num dig 1 
 lookup digit,[$c0,$f9,$a4,$b0,$99,$92,$82,$f8,$80,$90],ten
 PAUSEUS 5
 digit = num dig 2 
 lookup digit,[$40,$79,$24,$30,$19,$12,$02,$78,$00,$10],roy
 pauseus 5
 digit = num dig 3 
 lookup digit,[$c0,$f9,$a4,$b0,$99,$92,$82,$f8,$80,$90],phun
 pauseus 5 
   IF num <= 9 then 
         ten = $ff
         roy = $ff
         phun =$ff
         ShiftOut dat,clk,1,[unit,ten,roy,phun]
   else 
   IF num <= 99 then 
         roy = $ff
         phun =$ff
         ShiftOut dat,clk,1,[unit,ten,roy,phun]
   else
   IF num <= 999 then 
         phun =$ff
         ShiftOut dat,clk,1,[unit,ten,roy,phun]
   else
    ShiftOut dat,clk,1,[unit,ten,roy,phun]
   endif
   endif
   endif     
 Pauseus 10
 Low latch 
 Pauseus 10 
 high latch 
Return

display1:
  digit = num dig 0 
 lookup digit,[$ff,$09],unit
 PAUSEUS 5
 digit = num dig 1 
 lookup digit,[$ff,$C6],ten
 PAUSEUS 5
 digit = num dig 2 
 lookup digit,[$ff,$09],roy
 pauseus 5
 digit = num dig 3 
 lookup digit,[$ff,$09],phun
 pauseus 5 
   IF num <= 9 then 
         ten = $ff
         roy = $ff
         phun =$ff
         ShiftOut dat,clk,1,[unit,ten,roy,phun]
   else 
   IF num <= 99 then 
         roy = $ff
         phun =$ff
         ShiftOut dat,clk,1,[unit,ten,roy,phun]
   else
   IF num <= 999 then 
         phun =$ff
         ShiftOut dat,clk,1,[unit,ten,roy,phun]
   else
    ShiftOut dat,clk,1,[unit,ten,roy,phun]
   endif
   endif
   endif     
 Pauseus 10
 Low latch 
 Pauseus 10 
 high latch   
Return




Leave a Comment

*
= 3 + 0

Read previous post:
PC Based Digital Voltmeter Using PIC 16F877A

This is a simple voltmeter which measures 0-5V at a precision of 4.8 mV. This is a simple design using...

Close
Scroll to top