Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Bluetooth HC-05 to PC using PIC16F887

Status
Not open for further replies.
My last post updated.

Buy two of these.

**broken link removed**

Set voltage for TTL pins to 3.3V using switch. connect one to each BT module. Plug both BT modules to PC. Note down COM port used for each BT module. Do what I said in my previous post.
 
Last edited:

My last post updated.

Buy two of these.

**broken link removed**

Set voltage for TTL pins to 3.3V using switch. connect one to each BT module. Plug both BT modules to PC. Note down COM port used for each BT module. Do what I said in my previous post.

Hi again, someone came up with the idea un using CCS which has a "more complete" definition of RS232. I tested it and was perfect!

I guess using UART1_Init(9600) lacks of many parameters, meanwhile #USE RS232(BAUD,BITS,PARITY,XMIT,RCV) is more accurate.

Anyway, thanks for your patience, time and ideas!!
 

Attachments

  • LED_CCS.rar
    26.3 KB · Views: 123
Hi again, sorry to bother you again. I got a new issue and you seem to know a lot about this.

I can't make a full duplex transmission. If a do it PIC -> virtual terminal everything is okay. But when I also enable VT -> PIC, the microcontroller won't allow me to use any logic input, I mean, every switch and input I have configured goes dead.

Code:
valor=getc();
switch(valor)
{  
   case ('0'):
   X=desactivar();
   break;
   
   case('1'):
   X=activar();
   break;
}

I add that at the end of the code, so it checks if there's something in the buffer. But as I told you, the code before this just die. Should I use interrupts or something else instead of my code?
 

Please explain your circuit in more detail. A exact schematic would be helpful. Also explain in detail the working of your current code.
 

Ok so, the whole system is a car alarm, and you need to be capable of activate and deactivate it using either a RF control or a serial transmission.

The activate(), deactivate() and sound() functions change the state of the alarm using the X variable. Each one of them provides visual feedback (simulatin real car's lights), sends text notifications to the Virtual Terminal and change the value of X.

So the most complex scenario would be to deactivate it via RF, activate it again using the Virtual Terminal and finally to trigger the alarm using one of the 5 switches on port B.

This is were I fail. The system works totally fine when using only logic inputs and only PIC -> VT transmission. Bue when I add the VT -> PIC code, the microcontroller won't allow me to use the switches. I end up being able to de/activate the alarm only via VT, but ANY logic input (the 2 switches for activation/deactivation and the other 5 sensors) goes dead.

I attached you the code with comments and the simulation with some tags. Hope I could explained myself.

View attachment Code and simulation.rar
 

Please zip and attach the complete CCS C project files so that it can be compiled and tested.
 

hello,


MikroC and 16F => problem ...
Show you compilng messages window result...
di you get some "IRP_bit " inside ?
means bank access problem
because this PIC has not a lot of RAM memory.


sorry, i didn't see you take care you changed to CCS !

With MikroC , if FOSC is correctly defined inside the project , i never see unaccuarte UART speed..even with internal oscillator.
and with OSCTUNE you can adjust FOSC up to + - 5 % of deviation, but not necessary at all.
 
Last edited:

hello,

MikroC and 16F => problem ...
Show you compilng messages window result...
di you get some "IRP_bit " inside ?
means bank access problem
because this PIC has not a lot of RAM memory.


sorry, i didn't see you take care you changed to CCS !

With MikroC , if FOSC is correctly defined inside the project , i never see unaccuarte UART speed..even with internal oscillator.
and with OSCTUNE you can adjust FOSC up to + - 5 % of deviation, but not necessary at all.

I guess that's what I lived with MikroC, but yeah, CCS works a lot better.


Please zip and attach the complete CCS C project files so that it can be compiled and tested.

View attachment Proyecto.rar

Thanks! There you go
 

Please attach the complete CCS C project files. You didn't attach .pjt file. Without that I can't open you project. I think you have to use HF_INTOSC or something like that for 8 MHz internal oscillator in config bits.

In code your activate(), deactivate() and sound() functions are continuously called in while(1) and there are a lot of delays in those functions. So, your code will not work. For your PIC to receive data through BT module you have to use Serial ISR.
 

Sorry for being ignorant on CCS. I think I was editing a single source file instead of having created a project. Now I think I got it right.

View attachment Alarm.rar

I used those delays because it needs to give visual feedback like a real car, as I told you.

And yeah, maybe interrupt are the solution but I have never used them so I'm gonna reab about that.
 

I will write a code for you using mikroC. Post your circuit.
 

circuit.PNG

circuit2.png

Let me know if that's not what you are looking.

Thank you!
 

So, you are only testing in Proteus ? If yes, do you know that you can connect two BT modules to PC using TTL to USB adaptor and use COMPIM model in Proteus to connect to one BT module and communicate with it ? Try attached .hex file. Do not compile. Just use my .hex file in Proteus. I have used serial ISR.

Use my Proteus file. You need to use two VTs. One to receive and one to transmit. My Proteus file is v8.1 SP1.

Edir: working file attached. In the previous code I had not enabled global and peripheral interrupts. I think that was the mistake you had done in CCS C Code.
 

Attachments

  • bluetooth.png
    bluetooth.png
    55.7 KB · Views: 121
  • Bluetooth.rar
    98.4 KB · Views: 114
  • Bluetooth working.rar
    120.1 KB · Views: 104
  • bluetooth 1.png
    bluetooth 1.png
    73.5 KB · Views: 111
Last edited:
  • Like
Reactions: Nyakoi

    Nyakoi

    Points: 2
    Helpful Answer Positive Rating
OMG! That's awesome!!

I don't have the hardware right now, tomorrow I'm going to test it on the real circuit and I'll tell you. But it's awesome!! Thanks a lot!
 

Hi again, I finally was able to try it on hardware. Again, it didn't work :( it still sends random ASCII stuff.

Good thing is, I took your code to CCS and was able to make it work. So, in the night I will have an answer about if it transmits
 
Sorry for not telling you, but it worked on CCS. So it's done!! Thank you so much for all your help
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top