program METRO dim cnt as byte dim speed as byte dim cntn as byte 'dim tact as byte 'dim tactn as byte 'dim tone as byte dim keysts as byte dim rept as byte dim text as char[8] sub procedure interrupt inc(cnt) ' Increment value of cnt on every interrupt inc(rept) TMR0 = 0 INTCON = $20 ' Set T0IE, claer T0IF end sub sub procedure speed_dsp cntn = 2400/speed ByteToStr(speed, text) Lcd_Out(2, 1, text) ' Print text at LCD cnt = 0 SetBit(PORTB, 1) ' Set RB1 end sub sub procedure up_rtn if speed < 250 then inc(speed) speed_dsp end if end sub sub procedure down_rtn if speed > 30 then dec(speed) speed_dsp end if end sub main: trisa = $1F trisb = 0 ' Designate portb as output portb = 0 ' Initialize portb Lcd_Init(PORTB) ' Initialize LCD on PORTB Sound_Init(PORTB, 0) Lcd_Cmd(Lcd_CURSOR_OFF) ' Turn off cursor ' text = "METRO" ' METORO ' Lcd_Out(1, 1, text) ' Print text at LCD portb = $80 ' Initialize portb speed =60 speed_dsp ' tactn = 4 OPTION_REG = $87 ' Assign prescaler to TMR0 cnt = 0 ' Initialize cnt ' tact = 0 TMR0 = 0 INTCON = $A0 ' Enable TMRO interrupt keysts = $FE do 'SW0 START/STOP if testbit(keysts,0) = 1 then if testbit(PORTA,0) = 0 then clearbit(keysts,0) end if else if testbit(PORTA,0) = 1 then setbit(keysts,0) 'START/STOP Sound_Play(64, 200) if testbit(keysts,7)=1 then clearbit(keysts,7) else setbit(keysts,7) end if End if end if 'SW1 UP if testbit(keysts,1) then if testbit(PORTA,1) then else clearbit(keysts,1) rept=0 end if else if testbit(PORTA,1)then setbit(keysts,1) rept=0 up_rtn else if rept = 8 then rept=0 'UP routine up_rtn end if End if end if 'SW2 DOWN if testbit(keysts,2) then if testbit(PORTA,2) then else clearbit(keysts,2) rept=0 end if else if testbit(PORTA,2) then setbit(keysts,2) rept=0 'DOWN routine down_rtn else if rept=8 then rept=0 down_rtn end if End if end if ' if testbit(keysts,7)=0 then 'STATUS STOP cnt = 0 else 'STATUS START if cnt = cntn then ' cnt = 0 ' inc(tact) ClearBit(PORTB, 1) ' Clear RB1 ' if tact = tactn then ' tact = 0 ' tone = 48 ' else ' tone = 64 ' end if Sound_Play(64, 200) SetBit(PORTB, 1) ' Set RB1 end if end if loop until 0 = 1 end.