46 lines
843 B
Plaintext
46 lines
843 B
Plaintext
|
|
' ########### start ###########
|
||
|
|
' pic:PIC16F886
|
||
|
|
' ########### end ###########
|
||
|
|
|
||
|
|
'This program reads the potentiometer on AN0 and lights
|
||
|
|
' the LEDs connected to PORTB to form a bar graph
|
||
|
|
' that indicates how far the pot has been turned.
|
||
|
|
' This is similar to the volume display on a stereo
|
||
|
|
|
||
|
|
'Chip Settings
|
||
|
|
#chip 16F886,16
|
||
|
|
|
||
|
|
Dir PORTB Out
|
||
|
|
Start:
|
||
|
|
|
||
|
|
'Light all LEDs if pot turned all way to right
|
||
|
|
If ReadAD(AN0) > 230 Then
|
||
|
|
PORTB = b'00111100'
|
||
|
|
Goto Start
|
||
|
|
end if
|
||
|
|
|
||
|
|
'Three LEDs lit
|
||
|
|
If ReadAD(AN0) > 180 Then
|
||
|
|
PORTB = b'00011100'
|
||
|
|
Goto Start
|
||
|
|
end if
|
||
|
|
|
||
|
|
'Two LEDs lit
|
||
|
|
If ReadAD(AN0) > 100 Then
|
||
|
|
PORTB = b'00001100'
|
||
|
|
Goto Start
|
||
|
|
end if
|
||
|
|
|
||
|
|
'One LED lit
|
||
|
|
If ReadAD(AN0) > 10 Then
|
||
|
|
PORTB = b'00000100'
|
||
|
|
Goto Start
|
||
|
|
end if
|
||
|
|
|
||
|
|
'All LEDs off, Pot all way to left
|
||
|
|
If ReadAD(AN0) < 10 Then
|
||
|
|
PORTB = 0
|
||
|
|
end if
|
||
|
|
Goto Start
|
||
|
|
|