PDA

View Full Version : $



grounded
- 28th August 2005, 02:29
I'm learning to program in pbp-cdlite and looking at some code that I found, I saw this not sure but is "$0" and "$90" reseting all the flags and interupts.
in the OPTION_REG. AND INTCON

please explain

MAIN
OPTION_REG=$0
ON INTERRUPT GoTo bump
INTCON=$90

just trying to learn, asking for a little help

thanks

mister_e
- 28th August 2005, 09:00
$ is just a tag that mean it's a HEX value.

The PBP default 'radix' (if i can call it like that) is dec. So when you want to use Binary or Hex value, you must tell to the compiler.

MyVar=10 <= 10 decimal
Myvar =$90 <= 90 HEXadecimal
MyVar=%11110000 <= Binary value = $F0 = 240 decimal



please explain

MAIN
OPTION_REG=$0
ON INTERRUPT GoTo bump
INTCON=$90

Hard to say what it does if we don't know the PIC model. BUT many times, some of the interrupts flags are reset in the INTCON register.
Better and safer if you refer to your PIC datasheet to see what it do.

In my case, i prefer to use Binary as value. Easier to refer to the datasheet after few months/week/year/Century/milenium ...

INTCON=%10010000 is easier to figure out with the datashet than INTCON=$90 IMHO once again.
Also use Alias/Symbol to access directly to a specific register bit, Let's say


RCIF VAR PIR1.5 ' USART rx interrupt flag => Buffer full/empty
GO_DONE VAR ADCON0.0 ' ADC conversion status bit

grounded
- 29th August 2005, 02:16
thank you mister_e

I had alway used the $0 and $90 because a guy sent me some code and he used it. but I did not know what it meant. but it worked.
I 1st.did the code below with it and it worked. and then I did the code looking things up in the data sheet (like you suggested) and again it worked.

INTCON.4=1 'ENABLE RA2 EX. INT.
OPTION_REG.6=0 'SET RA2/INT FOR FALLING EDGE
INTCON.1=0 'RESET RA2/INT

ON INTERRUPT GoTo BUMP


I was thinking it might be some kinda wild card that reset everything.
don't laugh at my code I just learning.

DEVICE pic16f630
@ DEVICE pic16f630, INTRC_OSC_NOCLKOUT
@ DEVICE pic16f630, WDT_ON
@ DEVICE pic16f630, MCLR_OFF
@ DEVICE pic16f630, CPD_OFF '16F630 TEST
@ DEVICE pic16f630, BOD_OFF
@ DEVICE pic16f630, PWRT_ON
@ DEVICE pic16f630, PROTECT_OFF
DEFINE OSC 4
Pause 20000 'ALLOW TO STABILIZE AFTER POWER UP Allow
TRISA = %00101100 'MAKE A.5,A.2 & A.3 INPUTS
TRISC = %00000000 'MAKE ALL PORTC OUTPUTS

OPTION_REG.7 = 0 'ENABLE PULL-UPS
WPUA = %00110111 'WEAK PULL-UPS ON PORTA



SYMBOL GREEN = PORTC. 'GREEN LED
SYMBOL TRIG = PORTA.2 'INTERUPT INPUT
SYMBOL NOW = PORTA.5 'NONE INTERUPT INPUT
SYMBOL ORG = PORTC.2 'ORG LED
SYMBOL RED= PORTC.3 'RED LED

TRIG= 0
GREEN = 0
NOW = 0
ORG =0
RED =0
GREEN=1 'power up ok
Pause 4000
GREEN= 0
Pause 2000

IF NOW =0 Then GoTo LONG 'SELECT LONG OR BUMP
GoTo MAIN

MAIN
'OPTION_REG=$0
INTCON.4=1 'ENABLE RA2 EX. INT.
OPTION_REG.6=0 'SET RA2/INT FOR FALLING EDGE
INTCON.1=0 'RESET RA2/INT

ON INTERRUPT GoTo BUMP
'INTCON=$90


REFRESH:
Sleep 20 'EVERY 20 SEC. TURN A DIFFRENT LED ON FOR 6SEC. THEN OFF
ORG=1
Pause 6000
ORG=0
Sleep 20
GREEN=1
Pause 6000
GREEN=0
Sleep 20
RED=1
Pause 6000
RED=0



GoTo REFRESH

Disable


GoTo MAIN

BUMP:

GREEN = 1 'GREEN LED ON
Pause 1500 'FOR 1.5 SEC.
ORG=1 'ORG LED ON
Pause 1500 'FOR 1.5 SEC.
RED = 1 'RED LED ON
Pause 3000 'HOLD FOR 3 SEC.
GREEN=0 'GREEN LED OFF
ORG=0 'ORG LED OFF
RED=0 'RED LED OFF


INTCON.1=0
Disable

GoTo MAIN



LONG
GREEN=1
Pause 3000
GREEN=0
Pause 1000
RED=1
Pause 3000
RED=0
Pause 1000
ORG=1
Pause 3000
ORG=0

INTCON.1=0

GoTo LONG
Enable