3 Attachment(s)
dummies guide to serin/serout by a dummie
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!
Code:
'****************************************************************
'* 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
Code:
'****************************************************************
'* 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