Need help from PIC16F877A to VB2008 through rs232 serial port

Thread Starter

holybrings

Joined Apr 4, 2007
64
Hi, im a new VB learner and i need someone guidance to write a program. What i need to write is i get different signal from PIC16F877A and through serial port, i need to display diffrent text from different signal, Such as: Signal from portB.1 display 1, signal from portb.2 display 2.

Thanks.
 

CVMichael

Joined Aug 3, 2007
419
Well, there are 2 programs involved here...

First is the program on the microcontroller, did you make that program yet ?

Then there is the program on the computer (in VB.NET).

The microcontroller should simply send characters "1", or "2", when the bits on Port B enable, and the VB.NET program should just take the data that is comming from whatever comm port you are using for serial, and display the data.

By the way, what about if bit 1 and bit 2 are enabled, then what do you want to display ?

Give us more details on what you have done so far ? (at what stage are you ?)
 

Thread Starter

holybrings

Joined Apr 4, 2007
64
Im just handling VB.net. Microcontroller programming my friend handling. What im doing is a lift project. I need to display which floor the lift at. I'd been searching for sample but still can't find any.
Example:
Lift at level 2, portd.2 high(1), VB display "level 2".
Lift at level 3, portd.3 high(1), VB display "level 3".

Thanks for the reply.
 

BMorse

Joined Sep 26, 2009
2,675
there are some similarities to it but they are quite different VB2008 use the .net. VB4 is almost compatible to VB6.....

Basically what you will need :

on the uc side:

  1. UC with USART (which you already have)
  2. RS232 level converter IC (Such as the MAX232 TTL to Serial Level translator IC, which you already stated you have)
On the PC Side:

  1. PC with serial port (or a USB to serial converter dongle)
  2. VB with the MSCOMM Control loaded on the form.... (I have VB6 so I can not help you with code for VB.net, but I can give you a sample code for VB6)
This is all the hardware you will need to have uc "talk" to PC via RS232 (Serial)

What is the format of the data coming from uc? Is there any terminator characters used in the data transmission (Such as CRLF, CR, LF (CR = Carriage return, LF = Line Feed)? I will need to know how the data is transmitted and in what format before I can go any further.....

B. Morse
 

Thread Starter

holybrings

Joined Apr 4, 2007
64
Justb received a bad news, i need to write out my program for microcontroller to transmit any signal.
Start from the very beginning,
Write program for PIC,
this is what i search,
#include <htc.h> <=== This I don't understand
#include "USART.H" <=== Is this the usart you mean?
#include <stdio.h>
__CONFIG(0x3f71); <=== This I don't understand

Thanks for helping and sorry for knowing nothing.
 

BMorse

Joined Sep 26, 2009
2,675
Justb received a bad news, i need to write out my program for microcontroller to transmit any signal.
Start from the very beginning,
Write program for PIC,
this is what i search,
#include <htc.h> <=== This I don't understand
#include "USART.H" <=== Is this the usart you mean?
#include <stdio.h>

Thanks for helping and sorry for knowing nothing.
This are include files that are already written that you want the compiler to link to when the program is compiled before downloading it to the uc.


Since you have to start from the beginning.... why don't we do it right,
__CONFIG(0x3f71); <=== This I don't understand
first lets see the schematic for the uc circuit you are using, this will help in the coding for setting configuration bits for the uc...... the __CONFIG statement tells the compiler what configuration you want to use for the uc, such as oscillator type, and MCLR I/O pin usage, etc.

Once we have that on here then we will work on the code....

Do you have the circuit already built for the uc?

B. Morse
 

Thread Starter

holybrings

Joined Apr 4, 2007
64
Im now trying simple circuit to understand how uc through max232 -> rs232 -> vb.
when portd.2 high, portd.5 high
portd.3 high, portd.6 high
portd.4 high, portd.7 high
This what i set for the uc.
Currently i don't have any programmer, i just have the uc which got the above setting.
Now is 3am in the morning, so have to wait till morning only can get the programmer to test what i can write later on.
 

BMorse

Joined Sep 26, 2009
2,675
You can not write code for a circuit that doesn't exist yet (you can but it is futile, just simulating code does not guarantee it will actually work!), you have to have the working circuit in order to test it properly.....

B. Morse
 

BMorse

Joined Sep 26, 2009
2,675
the circuit is with my friend and it's working. For all the 3 ports as input, is connect with IR sensor.

Ok, then get the circuit diagram from your friend and post it here....

By the way, how do you know the circuit is working if you have to write the code for it from scratch??

Justb received a bad news, i need to write out my program for microcontroller to transmit any signal.
Start from the very beginning,
Write program for PIC,
I can't help you write the code if I don't know what is connected to what pin on the PIC16F877A... and another thing, what language are you going to write the code in? Assembly or C?

On the other hand I could write the code, but if I do, you will have to build my circuit to go with it, so unless you can help me help you, then we could always start from scratch, my way, and it is very possible you would end up with a useless program and circuit since you can't provide hardly any information to go by ;)

B. Morse
 
Last edited:

BMorse

Joined Sep 26, 2009
2,675
See how easy this is, I just created this circuit in about 5 minutes, and here is some sample code to go with it in both modes, but since I don't know anything else about your project this is a s far as I can go....

Here is the basic circuit, with ICSP....
PIC16F877A_RS232.png

here is the initialization code for both uart modes, do not know which one you will be using...

Asynchronous Transmitter/Receiver
Rich (BB code):
BSF STATUS,RP0 ; Go to Bank1
MOVLW <baudrate> ; Set Baud rate
MOVWF SPBRG
MOVLW 0x40 ; 8-bit transmit, transmitter enabled,
MOVWF TXSTA ; asynchronous mode, low speed mode
BSF PIE1,TXIE ; Enable transmit interrupts
BSF PIE1,RCIE ; Enable receive interrupts
BCF STATUS,RP0 ; Go to Bank 0
MOVLW 0x90 ; 8-bit receive, receiver enabled,
MOVWF RCSTA ; serial port enabled
Synchronous Transmitter/Receiver
Rich (BB code):
BSF STATUS,RP0 ; Go to Bank 1
MOVLW <baudrate> ; Set Baud Rate
MOVWF SPBRG
MOVLW 0xB0 ; Synchronous Master,8-bit transmit,
MOVWF TXSTA ; transmitter enabled, low speed mode
BSF PIE1,TXIE ; Enable transmit interrupts
BSF PIE1,RCIE ; Enable receive interrupts
BCF STATUS,RP0 ; Go to Bank 0
MOVLW 0x90 ; 8-bit receive, receiver enabled,
MOVWF RCSTA ; continuous receive, serial port enabled
In both examples the data is 8-bits, and the value to
load into the SPBRG register is dependent on the desired baud rate and the device frequency.

B. Morse
 

BMorse

Joined Sep 26, 2009
2,675
If you have access to Eagle Lite Version 5.1.0 or higher you can edit the circuit I did to reflect the rest of your circuit... include value for crystal...


Then post it back on here....

B. Morse
 

Attachments

Top