If you just want the short answer.....
I think you may have made a misstake with the pins
PORTA.3 is Data PIC>>>>PC (serout in pbp)
PORTA.4 is Data PC>>>>PIC (serin in pbp)
using PORTA.4 as an input is not a problem at all, if you want to use it as output you need a pull-up resistor to make it work.
Change is your sw and it might work better.
If you want a longer answer......
Yes datasheet can be really strange to read and understand, this we all have to accept. Training and experience will make it easier and even simple. This is fact.
Now to a different thing, making electronics with PIC inside is not that different from sport, training makes a difference and not all people have the same skills. It is easy to wish for a cool electronic gadget but much harder to make it. I am not writing this to put someone down, no I am writing this to explain how to get there and that is One Small Step at the Time. Don't expect to write a missileguiding SW the first day but eventually you will.
So I want to make a thing that can turn on and off LED from a PC, how would I do that?
A, Make a plan, with a good plan you will save much time later. Figure out what you want the circuit to do and what hardware you will need. You can always make the plan better later but you honestly need a plan before you start.
B, Test the hardware. Here is the best thing the undervalued Flash a LED program most usefull. Time spent verifying the hardware you will get back 1000 times later because when you see strange things you can rule out HW problems. If you can't flash a led you can not expect anything else to work ever....
C, If you want to connect to a PC do not start with a SERIN problem. Start with a SEROUT so you can see that you can send data to the PC. Even if you will not use it later?? YES!! Because it is easier to recieve data with a PC compared with a PIC, if you can send data to the PC it is more likely that the other way is working also. I almost always include a line early in the program to send SEROUT......... " PIC STARTED " so when I see this is hyperterminal I understand that the PIC is happy. It is also a great way of troubleshooting later because you can always send serial data to the PC to display arrays and other variables. When you can see the data on the PC you have proof that Baud and Mode are correct and you also know you are using the correct serial port on the PC.
D, Make sure you know where the PIC is in your progam before you do a Serin. Like other people said before use a start char to start the Serin function for example ":" or "X" or any other you want to use, just make sure you use one.... so do a serout first in your code
Serout............"PIC waiting for data" followed by a SERIN ........... that has a start char. Now you are sure that the PIC is waiting for char from the PC, now use the PC to send 2 char (start char + data char). After the Serin line I would put a new Serout line that has Serout.......... "Data recieved",#Data_Char Now I can see that the PIC moved forward in the program and what data was recieved. Please remember that ASCII and dec numbers can be confusing so double check or force the data to be in DEC fromat using the # function. IF you are not using a start char you are not sure that the data char is correct, serin will take any data and you will be in the land of trouble.
This is one small step at the time, the key to R&D and the best way to make progress. Later when you have everything working you can remove lines in the code that you are not using and the code becomes smaller and cleaner.
The good thing with PIC is that they are small computers, they do exactly what you tell them, the bad thing with them is they are small computers, they do exactly what you tell them.You can not expect the PIC to be forgiving in anyway, there are no help files incuded just the data sheet written by nerds for nerds.
To make the a circuit that turns on a LED is a very good project but it is not a simple project, it will take time, skill and patience but eventually you will get it to work.
Define OSC 10
include "Modedefs.bas"
ADCON1 = 7
TRISA = %010000 'RA4 as serial input, RA3 as serial output
TRISB = 0 'PortB used to ON the LED
CHAR var byte
PORTA.3=1
PORTB = 0
SEROUT PORTA.3,T9600,[" PIC started",10,13] 'I used hyperterminal to received the data
GOTO MAIN
PC_IN:
SEROUT PORTA.3,T9600,["Use : as start char",10,13] ' write :A in hyperteminal...
SERIN PORTA.4,T9600,[":"],CHAR
SEROUT PORTA.3,T9600,["Data from PC ",CHAR,10,13] '
RETURN
Main:
GOSUB PC_IN
GOTO MAIN
GOTO MAIN
Bookmarks