perides
- 11th July 2007, 20:20
At first, sorry if this is wrong place. I´m PICBASIC newbie and my English sucks.
I´m writing some code, and they work as I expect most of the time.
Folows the code:
Device 12F675
Config CPD_OFF, CP_OFF, BODEN_OFF, MCLRE_OFF, PWRTE_ON, WDT_OFF, INTRC_OSC_NOCLKOUT
XTAL = 4
CMCON = 7 ' Desliga a função do comparador
' +--------------------------+
'1 |Vdd Vss| 8
'2 |GPIO.5 GPIO.0/ANS0| 7
'3 |GPIO.4/ANS3 GPIO.1/ANS1| 6
'4 |GPIO.3/MCLR GPIO.2/ANS2| 5
' +--------------------------+
' ANSEL register's bits
Symbol ANS0 = ANSEL.0
Symbol ANS1 = ANSEL.1
Symbol ANS2 = ANSEL.2
Symbol ANS3 = ANSEL.3
Symbol ADCS0 = ANSEL.4 ' ADC conversion clock select bit
Symbol ADCS1 = ANSEL.5 ' ADC conversion clock select bit
Symbol ADCS2 = ANSEL.6 ' ADC conversion clock select bit
' ADCON0 register's bits
Symbol ADFM = ADCON0.7
Symbol VCFG = ADCON0.6
Symbol CHS2 = ADCON0.4 ' ADC channel select bit
Symbol CHS1 = ADCON0.3 ' ADC channel select bit
Symbol CHS0 = ADCON0.2 ' ADC channel select bit
Symbol GO_DONE = ADCON0.1 ' ADC Conversion status/ plus enable conversion-bit
Symbol ADON = ADCON0.0 ' ADC Enable bit: 1 = enabled, 0 = disabled.
TRISIO = %001011 ' output (0)
' GPIO.3 é somente input (1) digital
' input (1)
ANSEL.0 = 1 ' ANS0 input analogic
ANSEL.1 = 1 ' ANS1 input analogic
ANSEL.2 = 0 ' ANS2 input digital
ANSEL.3 = 0 ' ANS3 input digital
SERIAL_BAUD = 9600
RSOUT_PIN = GPIO.2
RSOUT_MODE = TRUE
RSOUT_PACE = 10
ADIN_Res 10
ADIN_TAD FRC
ADIN_STIME 50
Symbol LANTERNA = GPIO.4 ' Alias PORTD to LEDS
Symbol FAROL = GPIO.5
'-------[ASSIGN A VARIABLE FOR THE ADC RESULT]---------------------------
Dim AD_RESULT as ADRESL.WORD ' Convert the ADRESL register into a WORD variable
Dim mySet as Word
Dim myAtual as Word
Dim myCh AS BYTE
VCFG = 0 ' VREF is set to VDD of PICmicro
ADFM = 1 ' Right justify the ADC result
Delayms 500 ' Wait for PICmicro to stabilise
LANTERNA = 0
FAROL = 0
Loop:
MyCh = 0
Gosub Plota_ADC
mySet = AD_result
DelayMS 500
myCh = 1
gosub PLOTA_ADC
myAtual = Ad_result
if mySet <= myAtual then
FAROL = 1
Else
FAROL = 0
end if
DelayMS 500
Goto Loop ' Go back to loop and blink LED forever
End
PLOTA_ADC:
WARNINGS = OFF
BYTE_MATH = On ' Enable expression optimisation
ADCON0 = ADCON0 | (myCh << 2) ' Select the channel to read --> ADCON0 = ADCON0 | (nro. canal << 2 )
BYTE_MATH = OFF ' Disable expression optimisation
WARNINGS = On
AD_RESULT = ADIN myCh ' faz a leitura do canal myX
RSOut At 1,1,"ADC CHANNEL ", DEC myCh, " ", Dec AD_Result, 13 ' Display the result serially
Return
My problem is when RSOut was processed, if the FAROL is HIGH they go down and the corresponding LED turn off.
Can anyone help me?
I´m writing some code, and they work as I expect most of the time.
Folows the code:
Device 12F675
Config CPD_OFF, CP_OFF, BODEN_OFF, MCLRE_OFF, PWRTE_ON, WDT_OFF, INTRC_OSC_NOCLKOUT
XTAL = 4
CMCON = 7 ' Desliga a função do comparador
' +--------------------------+
'1 |Vdd Vss| 8
'2 |GPIO.5 GPIO.0/ANS0| 7
'3 |GPIO.4/ANS3 GPIO.1/ANS1| 6
'4 |GPIO.3/MCLR GPIO.2/ANS2| 5
' +--------------------------+
' ANSEL register's bits
Symbol ANS0 = ANSEL.0
Symbol ANS1 = ANSEL.1
Symbol ANS2 = ANSEL.2
Symbol ANS3 = ANSEL.3
Symbol ADCS0 = ANSEL.4 ' ADC conversion clock select bit
Symbol ADCS1 = ANSEL.5 ' ADC conversion clock select bit
Symbol ADCS2 = ANSEL.6 ' ADC conversion clock select bit
' ADCON0 register's bits
Symbol ADFM = ADCON0.7
Symbol VCFG = ADCON0.6
Symbol CHS2 = ADCON0.4 ' ADC channel select bit
Symbol CHS1 = ADCON0.3 ' ADC channel select bit
Symbol CHS0 = ADCON0.2 ' ADC channel select bit
Symbol GO_DONE = ADCON0.1 ' ADC Conversion status/ plus enable conversion-bit
Symbol ADON = ADCON0.0 ' ADC Enable bit: 1 = enabled, 0 = disabled.
TRISIO = %001011 ' output (0)
' GPIO.3 é somente input (1) digital
' input (1)
ANSEL.0 = 1 ' ANS0 input analogic
ANSEL.1 = 1 ' ANS1 input analogic
ANSEL.2 = 0 ' ANS2 input digital
ANSEL.3 = 0 ' ANS3 input digital
SERIAL_BAUD = 9600
RSOUT_PIN = GPIO.2
RSOUT_MODE = TRUE
RSOUT_PACE = 10
ADIN_Res 10
ADIN_TAD FRC
ADIN_STIME 50
Symbol LANTERNA = GPIO.4 ' Alias PORTD to LEDS
Symbol FAROL = GPIO.5
'-------[ASSIGN A VARIABLE FOR THE ADC RESULT]---------------------------
Dim AD_RESULT as ADRESL.WORD ' Convert the ADRESL register into a WORD variable
Dim mySet as Word
Dim myAtual as Word
Dim myCh AS BYTE
VCFG = 0 ' VREF is set to VDD of PICmicro
ADFM = 1 ' Right justify the ADC result
Delayms 500 ' Wait for PICmicro to stabilise
LANTERNA = 0
FAROL = 0
Loop:
MyCh = 0
Gosub Plota_ADC
mySet = AD_result
DelayMS 500
myCh = 1
gosub PLOTA_ADC
myAtual = Ad_result
if mySet <= myAtual then
FAROL = 1
Else
FAROL = 0
end if
DelayMS 500
Goto Loop ' Go back to loop and blink LED forever
End
PLOTA_ADC:
WARNINGS = OFF
BYTE_MATH = On ' Enable expression optimisation
ADCON0 = ADCON0 | (myCh << 2) ' Select the channel to read --> ADCON0 = ADCON0 | (nro. canal << 2 )
BYTE_MATH = OFF ' Disable expression optimisation
WARNINGS = On
AD_RESULT = ADIN myCh ' faz a leitura do canal myX
RSOut At 1,1,"ADC CHANNEL ", DEC myCh, " ", Dec AD_Result, 13 ' Display the result serially
Return
My problem is when RSOut was processed, if the FAROL is HIGH they go down and the corresponding LED turn off.
Can anyone help me?