Can't get 16F628A "If PortA.0 = 1 Then " to work

Status
Not open for further replies.

Bracer

New Member
This is the Code in PICBasic Pro:

@ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT 'Use Internal Clock
Input PortA.0 'Makes Port A, Pin 0 an Input.

Routine:

If PortA.0 = 1 Then
High PortB.0
Sound PortB.7, [120,15]
endif

Goto Routine

I don't understand why it doesn't react when PortA.0 IS high
 
Yes!
CMCON = 7

Thank you lilimike & Nigel Goodwin.

lilimike...why "CMCON = $07" ?

What's with the "$0" ?

Thanks
 
The $ means the value is hexadecimal, you can also use % for binary or simply 7 for decimal.
Of course 7 = 07 but since I used HEX I always use 2 digits which are from $00 to $FF

Its just a programming habit.

Mike
 
Last edited:
So a hexadecimal = decimal ?

because I tried CMCON = 7 and it works perfectly.

If $07 = 7, why would people use hex at all ?
Just use decimal all the way ?
 
Hexadecimal from 0 to F
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

Decimal from 0 to 15
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

As you can see both count up to 15 and both are equal up until 9

You will get a good explanation HERE with a comparison betwen HEX, DEC and Binary

Mike
 
The first 9 numbers of HEX are just like HEX, to convert it mentally you also have to know binary(at least the way I do it).
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…