http://www.picbasic.co.uk/forum/showthread.php?t=4994
Mistet E's Multicalc utility, just what you need for USART.
Robert
http://www.picbasic.co.uk/forum/showthread.php?t=4994
Mistet E's Multicalc utility, just what you need for USART.
Robert
Hi,
The 16F1829 has analog inputs on PortA, PortB and PortC but you're only disabling it on PortA. You absolutely MUST read the datasheet for these things. A pin in analog mode may seem to work when used as an output (but it will eventually bite you (RMW issue etc)), however when you're trying to read the state of that output pin (which is what you're doing (or originally did) in the ISR it will not give you the correct result. This is also clearly stated in the datasheet:And the same thing applies for ANSELB and C of course. As you can see, if the ANSELx register isn't set correct any READ of that port-pin will return 0.Setting the appropriate ANSELA bit high will cause all
digital reads on the pin to be read as ‘0’ and allow
analog functions on the pin to operate correctly
Also, I don't see you're using the ADC for anything yet you're setting ADCON1=7, why is that?
/Henrik.
http://www.picbasic.co.uk/forum/showthread.php?t=18529
If you want to see what you need to make pins digital.
Robert
Ok sensei, but if that's the case, why did it work fine before? Does high/low set the pin to digital as well as setting the tris bit? Or just a fluke. When it comes to computers, I don't really put much stock in 'accidents' except in the context of "I accidentally screwed that up" lol
I am not sure why it's there. This code started out on a 877a then went to something else when I smoked all 5 of those. Then back to 877a when more came in, then to this 1829 when I smoked all the new 877a's. This 1829 is actually the PICAXE20M2 that got me started on PIC vs Arduino. I came up on two of them scrapping something and saved them. Later, while going thru stuff, I realized they were MC's, and then what PICAXE was, and here I am..... But the code has been cut and pasted, and gone from MPLABX to MCS so idk....
I wasted many an unhappy day copying and pasting code that did not work.
I would start again and build up the program one step at a time. By adding small portions of code if the code stops working the small modification is the cause.
A good place to start is with the main menu, simply to test HSEROUT and HSERIN. Then take another very small step.
Steve Earl www.datageo.co.uk
Hi,
No, HIGH/LOW only handles the TRIS bit. I'm surprised, and a bit sceptical to be honest, that it really did work before. Then, of course, there might be something I'm missing - wouldn't be the first time, for sure.Ok sensei, but if that's the case, why did it work fine before? Does high/low set the pin to digital as well as setting the tris bit?
When moving from one PIC to another you really do need to verify that what you set the registers to applies to the new chip as well. Usually it does but certainly not always - especially if you move from one series to another. CMCON is one example, someone searches the forum, finds a post where it says that CMCON=7 disables the comparators. This is true for the some PICs but not all.... It's tedious (some might even say boring) but reading the datasheet really is a must and you certainly do learn a lot from doing it.
/Henrik.
Or you do like me and let Alldigital tell you what to do.
I go to the datasheet when I need a specific feature.
Robert
Well in this case I did that... It's just that it seems when trying to enable the hardware serial, there is A LOT of stuff to activate/set, and I just wasn't getting the combination correct. Still haven't... but haven't tried today either. I got sidetracked on another project... Gotta start a thread on that one now.
bit 7 of your config word should be 0 , having lvp enabled can lead to tears .
the comparator needs to be disabled to use your porta pins as digital
Last edited by richard; - 29th June 2014 at 05:44. Reason: typo
So you have your BT sorted out?
I use a BT chip on my boards with no converter. I have the BT chip running at 3.3v just like the PIC.
I am not sure what you are meaning by handheld device but if you are using a BT chip, look into making the app work on your Android phone.
Look into Basic4Android. Its a piece of cake to use. The wireless side is a bit cumbersome but once you get it going, its pretty slick. I use it to make an app to control up to 48 electrical motors sending data back and forth from the motor control boards to a tablet all wirelessly.
http://www.basic4ppc.com/index.html
If you get try it and need some help, email me at [email protected]
OK! I think I have my permanent solution. Since I had no problems with the first setup I did with this project where I was using physically attached buttons instead of serial commands to control the unit, I am adding a second PIC, whose only job in life is to sit at a serin command pause and await commands. Upon receiving a command, it will simply set a pin high for about 100ms, simulating a button press. Proof of concept already works... Just have two small snags... (and a large one too, but one step at a time lol)
1. I am trying to send via serial just one character. Capital A-F, depending on what combo of buttons is pressed by the user. It's not going thru. The BT is linked. The link seems good. When I hold a button down, it causes the serin pause to release, causing my debugging LED to flash. However, no command is processed. I'm sure it's a format problem or something, but I have tried 9 ways to sunday and I just can't seem to spot what I'm doing wrong. Also, if I shut down the master BT and log my laptop terminal into the dish PIC, sending A-F from the terminal works perfectly and it responds as expected.
2. Only buttons 3 and 4 work. Buttons 1 and 2 do not cause the LED to flash on the receiving end. I assume I'm missing something again about analog/digital, but this pic is very basic and has no ADC, and for the life of me I cannot figure out what I am missing. I have read thru every register in the datasheet, and I'm just not snapping to what it is...
Here is the code for the handheld device:
Here is the code for the PIC16F628A that is receiving the commands and "pressing buttons":Code:'**************************************************************** '* Name : Wireless Handheld Device '* Author : John Moore '* CHIP : PIC16F628A '* Date : May 28, 2014 '* Version : 1.0 '* Notes : This pic will eventually have 4 physical buttons and an LCD '* : as well as a BT device. Right now I just need it to send the '* ; serial commands, as I am monitoring the feedback with a terminal. '**************************************************************** #CONFIG __config 10000111110000 #ENDCONFIG button1 var PORTA.2 button2 var PORTA.3 button3 var PORTA.4 button4 var PORTB.3 TRISA.2 = 1 TRISA.3 = 1 TRISA.4 = 1 TRISB.3 = 1 cereal var byte TX var PORTB.2 TRISB.2 = 0 START: if button1 = 1 then cereal = "A" if button2 = 1 then cereal = "B" if button3 = 1 then cereal = "C" if button4 = 1 then cereal = "D" if (button2 = 1) and (button3 = 1) then cereal = "E" if (button1 = 1) and (button4 = 1) then cereal = "F" if cereal <> "X" then serout TX, 2, [cereal] pause 100 cereal = "X" GOTO START
Code:'**************************************************************** '* Name : On-Board Communication PIC '* Author : John Moore '* CHIP : PIC16F628A '* Date : May 28, 2014 '* Version : 1.0 '* Notes : This pic will never be more complicated than this. It's only '* : purpose in life is to get characters and push buttons. '**************************************************************** #CONFIG __config 10000111110000 #ENDCONFIG button1 var PORTB.7 button2 var PORTB.6 button3 var PORTB.5 button4 var PORTB.4 TRISB.7 = 0 TRISB.6 = 0 TRISB.5 = 0 TRISB.4 = 0 button1 = 0 button2 = 0 button3 = 0 button4 = 0 RX var PORTB.3 TRISB.3 = 1 LED var PORTA.1 TRISA.1 = 0 cereal var byte START: serin RX, 2, cereal if cereal = "A" then high button1 pause 140 low button1 endif if cereal = "B" then high button2 pause 140 low button2 endif if cereal = "C" then high button3 pause 140 low button3 endif if cereal = "D" then high button4 pause 140 low button4 endif if cereal = "E" then button2 = 1 button3 = 1 pause 140 button2 = 0 button3 = 0 endif if cereal = "F" then button1 = 1 button4 = 1 pause 140 button1 = 0 button4 = 0 endif LED = 1 pause 250 LED = 0 pause 250 GOTO START
Bookmarks