program METRO dim cnt as byte dim speed as byte dim cntn as byte dim tact as byte dim tactn as byte dim swdat as word sub procedure interrupt inc(cnt) ' Increment value of cnt on every interrupt TMR0 = 0 INTCON = $20 ' Set T0IE, claer T0IF end sub sub procedure speed_dsp cntn = 2400/speed cnt = 0 SetBit(PORTB, 1) ' Set RB1 SetBit(PORTB, 2) ' Set RB2 SetBit(PORTB, 3) ' Set RB3 end sub sub procedure get_sw ' Get Tact Time ClearBit(PORTA,4) PORTB = $70 NOP NOP tactn = ((not PORTA) AND $F) PORTB = $E0 NOP NOP swdat = ((not PORTA) AND $F) PORTB = $D0 NOP NOP swdat = swdat *10 + ((not PORTA) AND $F) PORTB = $B0 NOP NOP swdat = swdat *10 + ((not PORTA) AND $F) if swdat < 30 then swdat = 30 end if if swdat > 255 then swdat = 255 end if speed = swdat cnt = 0 tact = 0 end sub main: trisa = $0F trisb = $01 ' Designate portb as output portb = $0F ' Initialize portb Sound_Init(PORTA, 4) OPTION_REG = $07 ' Assign prescaler to TMR0 cnt = 0 ' Initialize cnt TMR0 = 0 INTCON = $A0 ' Enable TMRO interrupt get_sw speed_dsp do 'SW1 STOP if testbit(PORTB,0) = 0 then 'Set Sleep ClearBit(PORTB, 1) ' Clear RB1 ClearBit(PORTB, 2) ' Clear RB2 ClearBit(PORTB, 3) ' Clear RB3 Sound_Play(64, 100) SetBit(PORTB, 1) ' Set RB1 SetBit(PORTB, 2) ' Set RB2 SetBit(PORTB, 3) ' Set RB3 Delay_ms(300) INTCON = $90 asm sleep end asm 'Resume From Sleep 'SW1 START NOP NOP ClearBit(PORTB, 1) ' Clear RB1 ClearBit(PORTB, 2) ' Clear RB2 ClearBit(PORTB, 3) ' Clear RB3 Sound_Play(72, 100) SetBit(PORTB, 1) ' Set RB1 SetBit(PORTB, 2) ' Set RB2 SetBit(PORTB, 3) ' Set RB3 Delay_ms(300) cnt = 0 get_sw speed_dsp end if 'METRO Routine if cnt = cntn then ' cnt = 0 select case tact case 0 ClearBit(PORTB, 3) ' Clear RB3 Sound_Play(64, 200) SetBit(PORTB, 3) ' Set RB3 case 2,4,6,8 ClearBit(PORTB, 1) ' Clear RB1 Sound_Play(72, 200) SetBit(PORTB, 1) ' Set RB1 case else ClearBit(PORTB, 2) ' Clear RB2 Sound_Play(72, 200) SetBit(PORTB, 2) ' Set RB2 end select if tactn<>0 then inc(tact) if tact = tactn then tact=0 end if end if end if loop until 0 = 1 end.