PDA

View Full Version : 16f887 to 18f4685 transition



emerson
- 20th July 2012, 05:04
How would I go about configuring the 18f4685 so I can use the pins as simple I/O ports along with the serial communication pins 25 and 26? I have this configuration so far but it doesn't seem to work.



define device 18f4685
OSCTUNE = %11000000
OSCCON = %01110000
define OSC 8
CMCON = 0
ADCON0 = 7
ADCON1 = 7
ADRESH = 7
ADRESL = 7
INTCON = 0
INTCON2 = 0
INTCON3 = 0
IPR1 = 0
PIR1 = 0
PIE1 = 0


DEFINE HSER_RCSTA 90h ' Enable Serial PORT
DEFINE HSER_TXSTA 24h ' Enable transmit
DEFINE HSER_SPBRG 129 ' set USART to 9600 baud (when BRGH=1)
DEFINE HSER_CLROERR 1 ' Enable automatic overrun error
DEFINE LOADER_USED 1

The program I'm using was previously written on the 16f887, and the program work fine on that chip, so I'm assuming the 18f4685 isn't configured properly. The datasheet for the 18f4685 is below. Thanks for the help.

http://ww1.microchip.com/downloads/en/devicedoc/39761b.pdf

emerson
- 20th July 2012, 16:49
I forgot to add I'm using MicroCode Studio with PicBasic Pro.

mackrackit
- 20th July 2012, 18:21
But are you using MPASM and how are the configs set?

emerson
- 20th July 2012, 21:59
I am using MPASM v5.1 with Processor, Radix, Warning Level, Macro Expansion, and Hex Output set to default;
Generated File has Error and List files selected; Case Sensitive is also selected.

Are those what you meany by the configuration settings?

mackrackit
- 20th July 2012, 22:37
No, I mean these.
http://www.picbasic.co.uk/forum/showthread.php?t=543

emerson
- 21st July 2012, 07:33
No, I don't have anything nor have ever used anything like that before to my knowledge. I looked into the devices folder within my MPASM installation and I didn't see it in the list. Could that be why it isn't working?

mackrackit
- 21st July 2012, 13:21
You have never set the configuration for any chip? Not even changed the type of oscillator used? The *.inc file that needs changed is in the PBP directory.
Read through the thread I linked you too, figure out where all f the files are, then we can go from there.

emerson
- 21st July 2012, 16:10
Alright. I was able to find the .INC file and found the config bits at the bottom of the page. I came up with this so far but it doesn't work yet. Whenever I compile my program in MCS it gives me an error message for the "&" symbols.


@__CONIG_OSC_IRCIO67_1H &_FCMEN_OFF_1H &_PWRT_OFF_2L &_BOREN_OFF_2L &_WDT_OFF_2H &_MCLRE_ON_3H &_LVP_OFF_4L

And no I've never used this method before. I guess I've always gotten away with what I showed you in the initial post (until now), although now it seems incorrect.

mackrackit
- 21st July 2012, 16:36
Goto the *.inc file in the PBP directory and comment out the config lines so it looks like this:


;************************************************* ***************
;* 18F4685.INC *
;* *
;* By : Leonard Zerman, Jeff Schmoyer *
;* Notice : Copyright (c) 2008 microEngineering Labs, Inc. *
;* All Rights Reserved *
;* Date : 09/15/08 *
;* Version : 2.60 *
;* Notes : *
;************************************************* ***************
NOLIST
ifdef PM_USED
LIST
"Error: PM does not support this device. Use MPASM."
NOLIST
else
LIST
LIST p = 18F4685, r = dec, w = -311, w = -230, f = inhx32
INCLUDE "P18F4685.INC" ; MPASM Header
; __CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
; __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
; __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
; __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _BBSIZ_1024_4L & _XINST_OFF_4L
NOLIST
endif
LIST
EEPROM_START EQU 0F00000h
BLOCK_SIZE EQU 64


Then in your code;


'18F4685 TEST

@ __CONFIG _CONFIG1H, OSC_IRCIO67_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
@ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _BBSIZ_1024_4L & _XINST_OFF_4L

emerson
- 21st July 2012, 18:07
I'm sorry but that didn't seem to work either, but I have a few questions now. The WDT, was that set to 512 to somehow complement the 8MHz oscillation speed? Also this config line:


_BBSIZ_1024_4L

Does this let the chip change variable values while it's running or does it allow the chip to add code (a FOR...NEXT loop for example) to itself while in operation?


By the way, thanks for the time and help thus far

mackrackit
- 21st July 2012, 18:41
BBSIZ is the Boot Block Size.

Goto
C:\Program Files\Microchip\MPASM Suite
and find the file "P18F4685.INC"
That is where you will find all of the config options, near the end of the file. Do not modify this file.

So, you are saying that the code does not compile from post #9?

emerson
- 21st July 2012, 19:35
The code does compile 100% no errors, but it runs improperly. I am getting scrambled characters from the HSERIN/HSEROUT commands when the program is on the 18f4685, but when the program is on the 16f887 it works perfectly.

Here is how I have the 16f887 initialized (I did not use any config settings here)



Define device 16F887
Define OSC 8
ANSEL=0 ' A/D disabled for ANS0 to ANS7
ANSELH=0 ' A/D disabled for ANS8 to ANS13
CM1CON0 = 0 ' Disable comparators
CM2CON0 = 0 ' These default to disabled at POR, but just in case
CM2CON1 = 0
ADCON1 = 7
IOCB = 0
INTCON = 0

DEFINE HSER_RCSTA 90h ' Enable Serial PORT
DEFINE HSER_TXSTA 24h ' Enable transmit
DEFINE HSER_SPBRG 129 ' set USART to 9600 baud (when BRGH=1)
DEFINE HSER_CLROERR 1 ' Enable automatic overrun error
DEFINE LOADER_USED 1

and this is how the 18f4685 is initialized


define device 18f4685
@ __CONFIG _CONFIG1H, _OSC_IRCIO67_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
@ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _BBSIZ_1024_4L & _XINST_OFF_4L
OSCTUNE = %11000000
OSCCON = %01110000
define OSC 8
CMCON = 0
ADCON0 = 7
ADCON1 = 7
ADRESH = %00000000
ADRESL = %00000000
INTCON = 0
INTCON2 = 0
INTCON3 = 0
IPR1 = 0
PIR1 = 0
PIE1 = 0


DEFINE HSER_RCSTA 90h ' Enable Serial PORT
DEFINE HSER_TXSTA 24h ' Enable transmit
DEFINE HSER_SPBRG 129 ' set USART to 9600 baud (when BRGH=1)
DEFINE HSER_CLROERR 1 ' Enable automatic overrun error
DEFINE LOADER_USED 1

The rest of the program has remained unchanged.

mackrackit
- 21st July 2012, 20:07
Set
OSCTUNE = %00000000

And try this


DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 51 ' 9600 Baud @ 8MHz, 0.16%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator

emerson
- 22nd July 2012, 00:28
these changes make it so the only symbol transmitted the "≡" symbol instead of receiving mixed characters and symbols

mackrackit
- 22nd July 2012, 06:28
I think it is time to provide your code and schematic.

emerson
- 22nd July 2012, 13:26
I'll have to explain some things about the program. The project is a text-based video game system designed around multiple slave PICs and a master PIC, which communicates between both the console slave chips and game cartridge master/slave chips. The first chip to send serial data to the consoles master chip, is the console title chip. The data is then sent from the console master chip to a product called the Tellymate, which converts serial data to composite video based on hexadecimal characters from code page 437.

Links:
Tellymate - http://www.batsocks.co.uk/products/Other/TellyMate%20TTL%20Kit.htm
Code Page 437 - http://en.wikipedia.org/wiki/Code_page_437

Like I said before, when this program is on the 16f887, it works flawlessly.


'Define device 16F887
'Define OSC 8
'ANSEL=0 ' A/D disabled for ANS0 to ANS7
'ANSELH=0 ' A/D disabled for ANS8 to ANS13
'CM1CON0 = 0 ' Disable comparators
'CM2CON0 = 0 ' These default to disabled at POR, but just in case
'CM2CON1 = 0
'ADCON1 = 7
'IOCB = 0
'INTCON = 0



define device 18f4685
@ __CONFIG _CONFIG1H, _OSC_IRCIO67_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
@ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _BBSIZ_1024_4L & _XINST_OFF_4L
OSCTUNE = %00000000
OSCCON = %01110000
define OSC 8
CMCON = 0
ADCON0 = 7
ADCON1 = 7
ADRESH = %00000000
ADRESL = %00000000
INTCON = 0
INTCON2 = 0
INTCON3 = 0
IPR1 = 0
PIR1 = 0
PIE1 = 0

DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 51 ' 9600 Baud @ 8MHz, 0.16%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator


'DEFINE HSER_RCSTA 90h ' Enable Serial PORT
'DEFINE HSER_TXSTA 24h ' Enable transmit
'DEFINE HSER_SPBRG 129 ' set USART to 9600 baud (when BRGH=1)
'DEFINE HSER_CLROERR 1 ' Enable automatic overrun error
''DEFINE LOADER_USED 1


'~~~~~Variables~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~

'~~~~~Slave Chip~~~~~

Cart_Audio var portc.0 'Switch 1AB
Cart_Title var portc.1 'Switch 1CD

Audio var portc.2 'Switch 2AB
Keyboard var portc.3 'Switch 2CD

TellyMate var portd.0 'Switch 3AB
Slaves var portd.1 'Switch 3CD

Title var portd.2 'Switch 4AB
Cart_Master var portd.3 'Switch 4CD


CNT var byte
CNT2 var byte
SerDat var byte
MasterTrig var portd.4 'chip sensor pin
MasterCheck var bit
Master_Busy var porte.0 'timing pin
AudioTrig var portd.5 'chip sensor pin
TitleTrig var portd.6 'chip sensor pin
Assign_Var var byte
Key_Var var byte
Letter_CNT var byte
B1 var byte
B2 var byte
B3 var byte
B4 var byte
B5 var byte
B6 var byte
B7 var byte
B8 var byte
B9 var byte
B10 var byte
B11 var byte
B12 var byte
B13 var byte
B14 var byte
B15 var byte
B16 var byte
B17 var byte
B18 var byte
B19 var byte
B20 var byte
B21 var byte
B22 var byte
B23 var byte
B24 var byte
B25 var byte

'~~~~~Initialize TextBox~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~

trisc.0 = 0
trisc.1 = 0 'make all SLAVE pins OUTPUTS
trisc.2 = 0
trisc.3 = 0
trisd.0 = 0
trisd.1 = 0
trisd.2 = 0
trisd.3 = 0

trisd.4 = 1 'make Master_Trigger INPUT
trisd.5 = 1 'make Audio_Trigger INPUT
trisd.6 = 1 'make Title_Trigger INPUT

trise.0 = 1 'make Master_Busy INPUT

cart_audio = 0
Cart_title = 0
Audio = 0 'ALL Slaves set to
keyboard = 0 'no communication
tellymate = 0 'Motherchip to Tellymate
Slaves = 0 'Slave chips to Motherchip
title = 0
cart_master = 0
pause 30

'~~~~~AutoBaud~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AutoBaud:
tellymate = 1
pause 30 'mandatory 30ms pause for 4066 switching
hserout ["U", $1B, $45] 'transmit autobauding character, clear screen and return home
hserout [$1B, $76] 'allow text to continue on next line
'hserout [$1B, $66] 'CURSOR OFF
pause 500
tellymate = 0
pause 30

mastercheck = 0
cnt = 0
'~~~~~Program Start~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~

Start:

audio = 0
cart_audio = 1
GOTO LOAD_CARTRIDGE

slaves = 1 'allow slave communications
audio = 1 'enable audio communications
pause 30
hserout [0] 'play Intro sound file
pause 50
audio = 0 'disable audio communications
pause 30

title = 1 'enable TITLE SCREEN communications
tellymate = 1
pause 30
repeat
hserin [serdat] 'display TEXTBOX TITLE SCREEN
hserout [serdat]
until serdat = $BC 'last command sent by CARTRIDGE TITLE
pause 10 'allow SerDat to display everything
title = 0 'disable TITLE SCREEN communications
tellymate = 0
'pause 30

pause 1700

'Main:

'keyboard = 1 'enable typing
'pause 30
'hserin [serdat] 'receive keyboard data
'if serdat = $0D then 'IF RETURN has been pressed
' slaves = 0 'disable slave communications
' keyboard = 0 'disable typing
' pause 30 'and access boot menu
' hserout [$1B, $45] 'clear screen and cursor to 0,0
' goto cartridge_check
'else
' goto main 'repeat until RETURN is pressed
'endif

'~~~~~Cartridge Check~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
Cartridge_Check:
tellymate = 1 'enable Motherchip to TellyMate communications
pause 30
hserout [$1B, $45]
HSEROUT [$1B, $65] 'CURSOR ON
gosub next_line
hserout ["Checking Cartridge Port.", $0D, $0A, "Do Not Add/Remove Cartridge/"]
if mastertrig = 1 then 'IF portd.4 = 1, THEN
mastercheck = 1 'cartridge is there
else
mastercheck = 0 'cartridge is missing
endif

gosub loading_dots
gosub next_line
gosub next_line

'if cartridge is there and hasn't been removed~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if mastertrig = 1 and mastercheck = 1 then
gosub next_line
hserout ["Cartridge Found.", $0D, $0A, "Loading Cartridge Data/"]
Gosub Loading_dots
gosub next_line
gosub next_line
pause 200

hserout [$1B, $66] 'CURCOR OFF
hserout [$20, $F9, "Master Chip Located/", $0D, $0A]
pause 15
if audiotrig = 1 then
hserout [$20, $F9, "Audio Chip Located/", $0D, $0A]
endif
pause 15
if titletrig = 1 then
hserout [$20, $F9, "Title Chip Located/", $0D, $0A]
endif
pause 15

gosub next_line
gosub next_line
hserout [$1B, $59, 50, 34, $AF, $AF, "Press Return To Load Cartridge", $AE, $AE]
pause 10

tellymate = 0
pause 30

Cart_Loop:
slaves = 1
keyboard = 1
serdat = 0
repeat
hserin [serdat]
until serdat != 0
if serdat = $0D then
slaves = 0
keyboard = 0
goto load_cartridge
else
goto cart_loop
endif
endif

'if cartridge is missing and hasn't been added~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if mastertrig = 0 and mastercheck = 0 then
gosub next_line
hserout ["No Cartridge Was Found.", $0D, $0A, "Loading Text Editor/"]
gosub loading_dots
gosub next_line
gosub next_line

hserout [$1B, $66, $1B, $45]
gosub next_line
pause 100
hserout [$1B, $59, 33, 44, $AF, $AF, "Text Editor", $AE, $AE]
gosub next_line
gosub next_line
hserout [$1B, $65]

gosub text_editor
endif

'if cartridge was removed while loading~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if mastertrig = 1 and mastercheck = 0 then
gosub cart_error
endif

'if cartridge was inserted while loading~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if mastertrig = 0 and mastercheck = 1 then
gosub cart_error
endif


'~~~~~Text Editor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~

Text_Editor:
slaves = 1 'allow slave communications
keyboard = 1 'enable typing
pause 30
Text_Editor_Loop:
hserin [serdat] 'receive data from Keyboard
hserout [serdat] 'then display it
goto text_editor_loop

'~~~~~Subroutines~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~

Cart_Error:
slaves = 1
audio = 1
pause 30
hserout [2]
pause 50
audio = 0
pause 30
hserout ["Error/"]
slaves = 0
audio = 0
pause 500 'reset to Cartridge_Check
gosub next_line
gosub next_line
return


Loading_Dots:
pause 500
hserout ["."]
pause 500
hserout ["."] 'just some dots
pause 500
hserout ["."]
pause 1000
return


Next_Line:
hserout [$0D, $0A] 'jump to column 0 of next row
return

'~~~~~Load Cartridge~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~
Load_Cartridge:

slaves = 1 'allow slave communications

if audiotrig = 1 then 'if AUDIO chip is in CARTRIDGE
cart_audio = 1 'enable audio communications
pause 30
hserout [1] 'play Intro Cartridge sound file
pause 50
cart_audio = 0 'disable audio communications
pause 30
endif

if titletrig = 1 then 'if TITLE chip is in CARTRIDGE
tellymate = 1
cart_title = 1 'show title
pause 30
endif

'pause 30

Load_Cartridge_Loop:
repeat
hserin [serdat] 'receive data from Cartridge
hserout [serdat] 'then display it
until serdat = $BC 'last character of Cartridge Title Screen
pause 30
cart_title = 0
cart_audio = 0
pause 5000

hserout [$1B, $45] 'clear screen and cursor to 0,0
pause 30

'goto menu

'~~~~~Menu~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
Menu:

'tellymate = 1
cart_master = 0 'close master_chip communications
while master_busy = 1 'wait until master chip is finished working
'hserout ["."]
goto menu 'repeat until master_chip is done
wend

tellymate = 0 'disable text on screen
serdat = 0 'unassigned value for Menu loop
slaves = 1 'enable slave communications
cart_master = 1 'enable master_chip communications

repeat
hserin [serdat] 'receive subroutine number to execute
until serdat != 0 'wait to receive command

select case serdat 'read subroutine number
case $31 '1
goto Master_screen_loop 'if serdat = 1
case $32 '2
goto no_text_keyboard 'if serdat = 2
case $33 '3
goto keyboard_loop 'if serdat = 3
end select

goto menu

'~~~~~Master_Screen_Loop~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Master_Screen_Loop: 'display first/next screen of game

'hserout [$1B, $45] 'clear text from current screen
tellymate = 1 'enable text on screen
cart_master = 1 'enable master_chip communications

repeat
hserin [serdat] 'receive screen character from game
hserout [serdat] 'and display it on screen
until serdat = $00 'until terminate command is sent
tellymate = 0
goto menu

'~~~~~No_Text_Keyboard~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
No_Text_Keyboard: 'keyboard/cartridge transactions
tellymate = 0 'without text on screen
goto key_assignment

Key_Assignment:
cnt2 = 0 'assigned letter count variable
Letter_CNT = 0 'assigned letter quantity
serdat = 0

'~~~~~Receive Letter_CNT character amount~~~~~
slaves = 1 'enable slave communications
cart_master = 1 'enable Cart_Master communications
repeat
hserin [letter_cnt] 'receive letter amount
pauseus 14
' tellymate = 1
' hserout ["Letter_CNT = ", dec letter_cnt] 'display letter amount
until letter_cnt >= 1 and letter_cnt <= 25


'~~~~~Receive Corresponding Characters~~~~~
'slaves = 1 'enable slave communications
'cart_master = 1 'enable Cart_Master communications
cnt2 = 0
'pause 30
repeat
hserin [serdat] 'receive letter variable
pauseus 14
' tellymate = 1
' hserout [serdat]
write cnt2, serdat 'and store in EEPROM 0-24
cnt2 = cnt2 + 1
until cnt2 = letter_cnt 'until CNT2 equals letter amount
cart_master = 0
pause 30


cnt2 = 0 'reset CNT2 value


'~~~~~Keyboard_Loop~~~~~~~~~~~~~~~~~~~~~~~~
Keyboard_Loop:
'tellymate = 0
'slaves = 1 'enable slave communications
serdat = 0 'reset SerDat value
repeat 'repeat
cart_master = 0 'disabling cart_master communications
keyboard = 1 'enabling keyboard communications
hserin [serdat] 'and receiving data from the keyboard
until serdat != 0
'then
keyboard = 0 'disabling keyboard communications
cart_master = 1 'enabling cart_master communications
hserout [serdat] 'and sending keyboard data to cartridge

repeat
read cnt2, key_var 'save CNT2 value (EEPROM location) to Key_Var

select case serdat 'and compare Key_Var to keyboard input
' case $0D 'if keyboard = ENTER
' goto menu
case key_var 'if keyboard = requested character
goto menu
' case else 'if keyboard = anything else
' cnt2 = cnt2 + 1 'add 1 to CNT2
' goto keyboard_loop
end select
cnt2 = cnt2 + 1
until cnt2 >= letter_cnt 'until all requested letters
cnt2 = 0 'have been scanned
goto keyboard_loop

'~~~~~Yes_Text_Keyboard~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
Yes_Text_Keyboard: 'keyboard/cartridge transactions
'with text on screen
tellymate = 1
goto key_assignment


And here is the data sent from the Title chip, which is a 16f688.

Define device 16F688
Define OSC 8
ANSEL=0 ' A/D disabled for ANS0 to ANS7
'ANSELH=0 ' A/D disabled for ANS8 to ANS13
'CM1CON0 = 0 ' Disable comparators
'CM2CON0 = 0 ' These default to disabled at POR, but just in case
'CM2CON1 = 0
CMCON0 = 0
ADCON1 = 7
'IOCB = 0
'INTCON = 0

DEFINE HSER_RCSTA 90h ' Enable Serial PORT
DEFINE HSER_TXSTA 24h ' Enable transmit
DEFINE HSER_SPBRG 129 ' set USART to 9600 baud (when BRGH=1)
DEFINE HSER_CLROERR 1 ' Enable automatic overrun error
DEFINE LOADER_USED 1

'~~~~~Variables~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~`

SerDat var byte
Trigger var portc.3

trisc.3 = 1


'~~~~~Start-up Screen~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~

Main:

if trigger = 1 then
pause 100
if trigger = 1 then

'Use command "$1B, $59 to place cursor, and
'add (cursor location +32) for command coordinates

HSEROUT [$1B, $66] 'CURSOR OFF
'1 5 10 15 20 25 30 35 38
hserout [$C9, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $BB]
HSEROUT [$BA, $DE, $DC, " ", " ", $DB, $DC, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $DC, $DC, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA]
HSEROUT [$BA, " ", $DB, $DB, $DB, $DB, $DB, $DB, $DC, $DC, " ", " ", " ", " ", " ", " ", " ", " ", $DC, " ", " ", $DB, $DF, $DF, $DD, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA]
HSEROUT [$BA, " ", " ", " ", " ", $DB, $DD, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $DB, " ", " ",$DE, " ", " ", $DE, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA]
HSEROUT [$BA, " ", " ", " ", $DE, $DB, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $DE, $DF, $DB, $DF, $DD, $DE, $DB, $DB, $DD, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA]
HSEROUT [$BA, " ", " ", " ", $DB, $DD, " ", $DC, $DC, $DC, " ", $DE, " ", " ", " ", $DC, " ", " ", $DB, " ", " ", $DE, " ", " ",$DE, " ", $DE, $DC, $DC, $DC, " ", $DE, " ", " ", " ", $DC, " ", $BA]
HSEROUT [$BA, " ", $DD, $DE, $DB, " ", $DE, " ", " ", " ", $DD, " ", $DF, $DC, $DF, " ", " ", " ", $DB, " ", " ", $DE, " ", " ", " ", $DD, $DE, " ", " ", $DD, " ", " ", $DF, $DC, $DF, " ", " ", $BA]
HSEROUT [$BA, $DE, $DD, $DB, $DD, " ", $DB, $DF, $DF, $DF, " ", " ", $DC, $DF, $DC, " ", $DE, $DE, $DD, " ", " ", $DB, " ", " ", " ", $DD, $DD, " ", " ", $DE, " ", " ", $DC, $DF, $DC, " ", " ", $BA]
HSEROUT [$BA, " ", $DF, $DF, " ", " ", " ", $DF, $DF, $DF, " ", $DF, " ", " ", " ", $DF, " ", $DF, " ", " ", $DF, $DF, $DF, $DF, $DF, " ", $DF, $DF, $DF, $DF, " ", $DF, " ", " ", " ", $DF, " ", $BA]
HSEROUT [$CC, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $B9]
HSEROUT [$CC, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $B9]
HSEROUT [$BA, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA]
hserout [$BA, "P", "o", "w", "e", "r", "e", "d", " ", "B", "y", ":", " ", " ", $DC, $DC, $DC, " ", " ", " ", " ", " ", " ", $DE, " ", $DE, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA]
HSEROUT [$BA, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $DB, " ", $DC, " ", " ", " ", " ", " ", $DE, $DD, $DB, " ", $DC, " ", " ", $DC, " ", " ", $DC, " ", " ", " ", $BA]
HSEROUT [$BA, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $DB, $DE, $DC, $DD, $DD, $DD, $DD, $DD, $DE, $DE, $DE, $DE, $DC, $DD, $DF, $DB, $DF, $DE, $DC, $DD, " ", " ", $BA]
HSEROUT [$BA, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $DB, $DE, $DC, " ", $DD, $DD, $DE, " ", $DE, " ", $DE, $DE, " ", $DD, " ", $DB, " ", $DE, $DC, " ", " ", " ", $BA]
HSEROUT [$BA, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "T", "M", $BA]
HSEROUT [$BA, " ", " ", "A Product of www.Batsocks.co.uk", " ", " ", " ", $BA]
hserout [$CC, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $B9]
HSEROUT [$BA, " ", "Circuit Design and Programming By:", " ", $BA]
hserout [$ba, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA]
hserout [$BA, " ", " ", " ", " ", " ", " ", "Robby Hannan, March 2012", " ", " ", " ", " ", " ", " ", $BA]
HSEROUT [$BA, " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", $BA]
HSEROUT [$C8, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $CD, $BC]
hserout [$00]
goto main

else
goto main
endif 'Change line 75 PAUSE time to length of picture scroll + music
endif

goto main

end

mackrackit
- 22nd July 2012, 16:12
Is the 18f4685 connected to the TellyMate with the same hardware as the 16f887 was?
Sorry that I am not able to spot the problem right off.

emerson
- 22nd July 2012, 16:20
hey no need to apologize, but yes, the 18f4685 is attached to the same hardware as the 16f887. I chose the 18f4685 because it had an identical pinout to the 16f887 so all I would have to do is swap the chips on my breadboard. I would provide a schematic if I had one but I can't draw one up in multisim.

grahamg
- 22nd July 2012, 19:51
I think your problem may be caused by your oscillator frequency. When using the 16f887 what oscillator were you using? When using the usart frequency you should use a crystal oscillator for stable operation. Your oscillator configuration for the 18f chip appears to use internal irc oscillator which may not be good enough for reliable operation.

emerson
- 22nd July 2012, 20:23
I have always used the 8 MHz internal oscillator. I've done serial communications with the 16f887, 16f688, and 16f630 all with internal oscillators (simply because I don't have any crystals around to use), but I do agree that it's some kind of timing error.

mackrackit
- 23rd July 2012, 06:04
Poking around the datasheet a bit I notice that the setting for TRISC.6 is opposite for the 18F4685 compared to the 18F4550. I do not have an 18F4685 so I can not test.

I wonder if PBP is setting these correctly, not often but sometimes things are over looked, but this chip has been around for awhile....

Anyways, it can not hut to set this manually in your code.
From the datasheet, section 18:


The pins of the Enhanced USART are multiplexed
with PORTC. In order to configure RC6/TX/CK and
RC7/RX/DT as an EUSART:
• bit SPEN (RCSTA<7>) must be set (= 1)
• bit TRISC<7> must be set (= 1)
• bit TRISC<6> must be cleared (= 0) for
Asynchronous and Synchronous Master modes,
or set (= 1) for Synchronous Slave mode

emerson
- 23rd July 2012, 14:00
Good eye. I'll try that and get back to you later.

emerson
- 23rd July 2012, 22:26
I added this to my code but yet again nothing has happened. I also have tried it without TXSTA and BAUDCON.


TXSTA = %10100000
RCSTA = %10110000
BAUDCON = %10000010
trisc.6 = 0
trisc.7 = 1