Hello insider world!
my attempt to send a word and display it on a LCD works with serin and debug, now I try with
HSEROUT/HSERIN and of course it fails.
using two 16F628A with a single canned 20Mhz oscillator.
'************************************************* *******************************************
' HSEROUTFAST1
'16F628A canned 20MHz osc extern
' should count pulses on porta.0 and send by USART to PIC # 2
'************************************************* *******************************************
'
' DEFINITIONS
@__config _EXTCLK_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
Include "modedefs.bas"
CMCON=%00000111
DEFINE OSC 20
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h '9600 baud rate, BRGH=1
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 129 '25 for 4MHz
DEFINE HSER_CLROERR 1
Cnt VAR Word ' Cnt is a word variable
' START OF MAIN PROGRAM
' ' Cnt is a word variable
CMCON = 7 ' RA0-RA3 are digital I/O
TRISA = %11111110 ' PORT A1 is input
TRISB = %11111111 ' RB output
cnt = 0
main:
COUNT PORTA.0,100,cnt ' Count for 1 second
RCSTA.7 = 1 'usart enabled
HSEROUT [0,cnt ,10,13]
PAUSE 10
RCSTA.7 = 0 'usart disabled
goto main
END ' End of program
and here the recieving program :same setup as above + an lcd in standard configuration.
'************************************************* *******************************************
' PIC#2 : 16F628A 20 Mhz extern canned oscillator same as PIC#1
' should recieve the variable cnt and show it on LCD
'
'************************************************* *******************************************
'
' DEFINITIONS
@__config _EXTCLK_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
Include "modedefs.bas"
CMCON=%00000111
DEFINE OSC 20
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h '9600 baud rate, BRGH=1
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 129 '25 for 4MHz
DEFINE HSER_CLROERR 1
Cnt VAR word ' Cnt is a word variable
inputData var word ' variable to receive data into
' START OF MAIN PROGRAM
'
CMCON = 7 ' RA0-RA3 are digital I/O
TRISA = 0 ' PORT A is output
TRISB = %11111101 ' RB1 is Input others output
cnt = 0
main:
Hserin [inputData]
cnt = inputData
LCDOUT $FE,2
LCDOUT "cnt=", DEC4 cnt
goto main
END ' End of program
I know HSerin needs some registers to enable and disable but thats too far for me now.
Experience: you can force a 4Mhz PIC16F628A to run on 20MhZ with an extern osc..hehe, everything works..tried some ..hihi
Bookmarks