So if I want to use an analog input for port A I need to include a line of code such as this:
ANSEL = %00001111
if I want PORTA.0-PORTA.3 to be analog inputs, but if I'm getting serial data in through these pins can I keep them as digital input/output ports and just use the first digital high that comes in from the serial information to activate some output on another pin? Also I found a project that used the code 'ADCON1.7 = 1' to align bit 7 to be right justified and then 'ADCON1.4 = 0' and 'ADCON1.5 = 0' to default to using Vref. When I'm not doing any analog to digital conversion I shouldn't need any of these commands should I?
Basically, the deal is, you have to look at the register's default values (the little numbers above the blocks in the register descriptions in the datasheets). If it says 'R/W-0', then it's a read/write register and on RESET(MCLR), it's set to '0'...and so on...
So basically, you're on the right track with what you said. I don't have the datasheet handy, you could be right on the bits, if that's what you read, then that's what it is.
Details,Details,Details. FACTs in the FAQ section.
Check the data sheet for the PIC you are using. I have not used the 16F88 yet, some PICs are a little different.So if I want to use an analog input for port A I need to include a line of code such as this:
ANSEL = %00001111
Something like that.if I want PORTA.0-PORTA.3 to be analog inputs, but if I'm getting serial data in through these pins can I keep them as digital input/output ports and just use the first digital high that comes in from the serial information to activate some output on another pin? Also I found a project that used the code 'ADCON1.7 = 1' to align bit 7 to be right justified and then 'ADCON1.4 = 0' and 'ADCON1.5 = 0' to default to using Vref. When I'm not doing any analog to digital conversion I shouldn't need any of these commands should I?
Each analog pin can be set to digital or analog.
If you use serial the pin will have to be set as digital - true.
If you are not using any analog, set all as digital.
NO, serial does not work that way. When a serial signal say XYZ comes in something could be made to happen. If serial ABC comes in something else could happen. If serial QST comes in it could be ignored.first digital high that comes in from the serial information to activate some output on another pin?
A digital LOW state is 0 to around 2 volts. Digital HIGH is around 3.6 to 5 volts.
In between is FUZZY![]()
Dave
Always wear safety glasses while programming.
What if I told my partner to have his program send an ASCII character, say, "A" before any message is sent to our bluesmirf which is connected to our LCD through my PIC. Could I use that character to activate a series of commands that would send the correct hexadecimal code to the LCD to activate the backlight then wait 10 seconds then send the code to turn off the backlight? Something like this:
INCLUDE "modedefs.bas"
SEROUT PORTB.1,T9600,[1]
SERIN PORTA.1,T9600,["A"]
IF PORTA.1 = "A" THEN
PORTB.1 = $FE
PORTB.1 = $96
PAUSE 10000
PORTB.1 = $FE
PORTB.1 = $80
endif
I'm almost sure that's not right since I'm not sending out serial data just hexadecimal numbers, but can I use the serin/serout commands inside the IF/Then statement? or am I closer than I think.
INCLUDE "modedefs.bas"
SEROUT PORTB.1,T9600,[1]
SERIN PORTA.1,T9600,["A"] ---- this would only wait for the "A" character, it wouldn't save it anywhere or do anything with it...
IF PORTA.1 = "A" THEN ---- again, you haven't saved your "A" character anywhere
PORTB.1 = $FE ---- it's a bit output that you're trying to send a byte out of, that don't work, but I think you already know that...
What you probably want is:
INCLUDE "modedefs.bas"
inputdata var byte
main:
SEROUT PORTB.1,T9600,[1] 'trigger something somewhere else
waitloop:
SERIN PORTA.1,T9600,[inputdata]
if inputdata <> "A" then goto waitloop
serout portb.1,T9600,$FE, $96: pause 10000:serout portb.1,T9600,$FE,$80:goto main
goto main
I'm now working on sending serial data from our bluesmirf through the pic straight into the serial input port of our LCD. One of my partners currently is working on his java program and has the pic at home so I can't test the code that I have till tomorrow afternoon, but the code I wrote compiles fine and uses a similar format to the code that skimask showed me (baring the backlight activation part).
@ DEVICE MCLR_OFF, PROTECT_OFF, WDT_OFF
INCLUDE "modedefs.bas"
DEFINE LCD_LINES 2
ANSEL = %00000000
SERIALDATA var byte
STORAGE VAR BYTE
MAIN:
SEROUT PORTB.0,T9600,[STORAGE]
SEARCHLOOP:
SERIN PORTA.0,T9600,[SERIALDATA]
if SERIALDATA <> "A" then goto SEARCHLOOP
SERIN PORTA.0,T9600,STORAGE: SEROUT PORTB.0,T9600,[STORAGE]
GOTO MAIN
I'm not sure if SERIN, and SEROUT work this way, but what I understand from what I've read and seen is that the serin command will put it's data in the variable byte "STORAGE" that I created and then the SEROUT will send out the serial data that is stored in that variable byte. Does the code look good? Or am I a bit off on my logic. Also I'm not fully sure what the first line does, but I saw it on another project doing serial communication with a PIC16F88 and what I do know about those commands it seems to make sense, it also hasn't hurt anythign I've done so far.
PS:
Skimask your smart "S-M-R-T....... I mean S-M-A-R-T" thanks a lot for your help so far.
Explanations for all those configurations are in the datasheets under 'Special Features' and elsewhere.
Keep in mind, there's literally dozens of people here much more adept with PBP/MPASM, etc.Skimask your smart "S-M-R-T....... I mean S-M-A-R-T" thanks a lot for your help so far.
AlaskanEE -
Don't know if you ever got your hands on a PBP manual, but if you haven't, you can download one from www.melabs.com. Might help with some of those questions regarding syntax.
Wisdom is knowing what path to take next... Integrity is taking it.
Ryan Miller
Bookmarks