PDA

View Full Version : dummies guide to serin/serout by a dummie



earltyso
- 16th April 2008, 03:22
Hello All,
I have come to this forum so many times for help and have always been able to find it conditinal only that I give the coding my best shot before asking blindly researched topics.
I have really appreciated all the help I have been given and just wanted to give back in some small way. I realize that I am no Jedi Master even after 3 years of weekend warrior coding, but I thought hey this works for me, maybe I can help someone else out.

This code does the following...
Allows the user to serial out from a PIC16F628A to a PIC16F877 and then output the entire ASCII Table to a 4x20 line LCD. (see pics). You can also turn to page 207-210 of the PPB manual to see where my code is going. The data is also sends binary "B0" to PORTC of the 16f877 so you can compare ASCII key displays,decimal, binary, and hexidecimal values all at the same time.

Yes my coding is not perfect, and you can certainly modify this code to work on almost all pics, give it a shot and let know what you think. Once again this was written by a padawon but I think it make milk of the meaty ASCII table.

Enjoy!



'************************************************* ***************
'* Name : SERIAL TRANSMITTER BOARD *
'* Author : TYSON EARL *
'* Notice : Copyright (c) 2008 Ty's Custom Electronics *
'* : All Rights Reserved *
'* Date : 3/19/2008 *
'* Version : 2.0 pic16f628a *
'* Notes : once switch is pressed on breadboard code begins *
'* : sending values 0-127 (see ASCII table) every sec * *
'************************************************* ***************
Include "modedefs.bas"
Define OSC 4
CMCON = 7

input PORTB.0
OUTPUT PORTB.5
OUTPUT PORTA.0
SWITCH VAR PORTB.0
Buzzer VAR PORTB.5
X VAR BYTE
B0 var byte

INTRO:
for x = 0 to 1
high buzzer
pause 50
low buzzer
pause 50
next x

main:
while switch = 0
FOR B0 = 0 to 127
SEROUT PORTA.0,N2400, ["A",B0]
PAUSE 1
pause 1000
NEXT B0
wend
GOTO INTRO
END





'************************************************* ***************
'* Name : SERIAL RECIEVER BOARD *
'* Author : TYSON EARL *
'* Notice : Copyright (c) 2008 *
'* : All Rights Reserved *
'* Date : October 20th *
'* Version : 2.0 PIC16F877 *
'* Notes : This program recieves serial data in and outputs *
'* : display, decimal, binary, and hex to 4x20 lcd *
'************************************************* ***************

INCLUDE "modedefs.bas"
DEFINE OSC 12
ADCON1 = 7 'all digital inputs, good to go now!!
DEFINE LCD_LINES 4
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_COMMANDUS 2005
DEFINE LCD_DATAUS 55
DEFINE ADC_BITS 8

Row1 CON 128 'constant for LCD line1
Row2 CON 192 'constant for LCD line2
Row3 CON 148 'comstant for LCD line3
Row4 CON 212 'constant for LCD line4

input PORTA.0 'SERIAL INPUT
Output PORTA.5 'L1
Output PORTE.0 'L2
Output PORTE.1 'L3
Output PORTE.2 'L4
Output PORTC.0 'L5
Output PORTC.1 'L6
Output PORTC.2 'L7
Output PORTC.3 'L8
INPUT PORTD.0 'RX1
INPUT PORTD.1 'RX2
Output PORTD.7 'RELAY4
Input PORTD.5 'BACK
Input PORTD.4 'NXTSLT
Input PORTC.7 'UP
Input PORTC.6 'DOWN
Input PORTC.5 'RX6
input PORTC.4 'RX5
input PORTD.3 'RX4
input PORTD.2 'RX3
B0 VAR byte

low l1:low l2:low l3:low l4:low l5:low l8:

Loop1:
lcdout 254, 1
while back = 0:wend
LCDOut 254,1
LCDOut 254,Row1," KEYPAD Monitoring "
LCDOut 254,Row2," beginning in ... "
pause 1000
LCDOut 254,Row3," 3"
pause 1000
LCDOut 254,Row3," 2"
pause 1000
LCDOut 254,Row3," 1"
pause 1000
lcdout 254,1

FROMKEYPAD:
LCDOut 254,1
bubba:
SERIN PORTA.0,N2400,["A"],B0
LCDOut 254,Row1,"DISPLAY ",B0
lcdout 254,Row2,"DECIMAL ",DEC b0
LCDOut 254,Row3,"BINARY ",BIN B0
lcdout 254,Row4,"HEX $ ",HEX b0

PORTC.3 = B0.0
PORTC.2 = B0.1
PORTC.1 = B0.2
PORTC.0 = B0.3
PORTE.2 = B0.4
PORTE.1 = B0.5
PORTE.0 = B0.6
PORTA.5 = b0.7
pause 200
GOTO bubba

mackrackit
- 16th April 2008, 13:08
Nice job.

What developing board are you using?

duncan303
- 16th April 2008, 13:19
Great stuff

gis a clue as the reason for line label Bubba: :D

curious

Duncan



____________

earltyso
- 16th April 2008, 17:28
This board you see pictured is one of 4 boards I had made for prototyping my wife's yard (light and sprinkler) controller. I just left off alot of the extras on this board like the linx reciever decoder, relays, fets, dip switch for adressing. In college I designed PCB's for a small potato harvesting company in Idaho....

www.spudnik.com

I really got into PCB manufacturing, wireless data communications, switchmode devices, firmware, etc. That's also where I got started with PBP as my boss programmed exclusively in PBP. Since that time I have been doing my own PCB's and software mostly for fun.

www.tyscustomelectronics.com

bubba: oh yes, I was talking with friend on the phone while I was coding up and it just seemed like the appropriate name for that little subroutine at the time. no good reason. haha

mbox
- 9th October 2008, 07:22
Hi!
Just a begginer to pic programming, I have a pic16F628A and I'm trying to find a code & schematic for this mcu to use the internal clock and recieve data from hyperterminal that will lit Led1,Led2 and Led3. Hope you can help and thanks in advance....


regards,
mbox

Archangel
- 9th October 2008, 08:16
Hi!
Just a begginer to pic programming, I have a pic16F628A and I'm trying to find a code & schematic for this mcu to use the internal clock and recieve data from hyperterminal that will lit Led1,Led2 and Led3. Hope you can help and thanks in advance....


regards,
mbox
Welcome to the forum !
Here is the deal, offered to all newbies. Write some code and we will help you make it work. Some here may do handovers, most do not, but most are willing to share their experience and knowledge. Why no handouts, because you learn very little from them, whereas if you struggle, you learn, and before long you are helping others. So that said let's get busy with some code.<br> So for starters do this, write a program to turn on those LEDs either by changing a port status or just make a loop to flash them in sequence, it doesn't have to be pretty, or even work, but it should show you made an effort to.

mbox
- 9th October 2008, 17:18
hi!
thanks for the reply.. I have this simple code that will lit the LED1,LED2 and LED3...using Pic16F682A. But I Want to control them to hyperterminal. Can you show me how to enable the RX on RB1?

CMCON = 7 ' PortA = digital I/O
VRCON = 0 ' A/D Voltage reference disabled
TRISB = %11110000

begin:
high PortB.0
pause 100
low PortB.0
pause 100
high PortB.1
pause 100
low PortB.1
pause 100
high PortB.2
pause 100
low PortB.2
pause 100
goto begin

aratti
- 9th October 2008, 17:53
You cannot connect pic directly to the PC Rs232 port! You will need a maxim 232 as an interface.

Read the manual where you will find some example of Tx and Rx.

When You have setup your hardware, than remember you will send bytes via RS232 so your pic will need to decode the bytes sent via hyperterminal and act upon it. For instance I can set all 8 ports B to ON sending via RS232 "255" or set them all to OFF sending a "0".

Hope it will help you

mackrackit
- 9th October 2008, 18:53
You cannot connect pic directly to the PC Rs232 port! You will need a maxim 232 as an interface.

Correct only if you are using the hardware serial from the PIC.
If you plan to use SERIN or SERIN2 then all you have to do is use inverted mode.
It is all in the manual :)

Archangel
- 9th October 2008, 20:15
That's a start . . . .
now add a byte variable and a word variable, give them names meaningful to you, like LED1 or OUTPUTLED1 or MBOXVAR1, right now they will just be there, not doing anything, and compile to check for errors.
edit: Set your port latch before the Tris register, that way when the tris turns the port to outputs, they will be set at the desired state, next we will work on config statements.

mbox
- 10th October 2008, 01:48
Good morning!!!
This is my update code, adding 2 variables, when complied it says 85 words used.


[codes]
CMCON = 7 ' PortA = digital I/O
VRCON = 0 ' A/D Voltage reference disabled
TRISB = %11110000

PortB = %00000000 ' Turn pins to low state
Led1 var byte ' Led1 as a byte(8 bits) variable
myvar var word ' myvar as a word(16 bits) variable

begin:
high PortB.0
pause 100
low PortB.0
pause 100
high PortB.1
pause 100
low PortB.1
pause 100
high PortB.2
pause 100
low PortB.2
pause 100
goto begin
[\codes]

thanks for the guidance,

Archangel
- 10th October 2008, 03:12
OK, let's not hijack Earl's thread any farther Please start a new thread in mel PbasicPro , and study this thread:http://www.picbasic.co.uk/forum/showthread.php?t=543
To gain some insight on the next thing we are going to do, after which you will compile a working program into your PIC, which you wrote.