Have made some progress in isolating the problem. Finally found a laptop with true serial interface so I could avoid use of USB-to-serial adapter cable. To confirm EasyPic6 interface was working I programmed a PIC16F877 chip with the standard loopback test mikroBasic code that came as sample with the EasyPic6. With this code the serial interface worked fine. This confirms there is nothing wrong with the serial interface hardware in the EasyPic6. For reference here is that simple code:
Code:
' *
' * Project name:
' UART (Simple usage of UART module library functions)
' * Copyright:
' (c) Mikroelektronika, 2009.
' * Revision History:
' 20080930:
' - initial release;
' - 20090720 - modified by Slavisa Zlatanovic;
' * Description:
' This code demonstrates how to use uart library routines. Upon receiving
' data via RS232, MCU immediately sends it back to the sender.
' * Test configuration:
' MCU: PIC16F887
' http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf
' Dev.Board: EasyPIC6
' http://www.mikroe.com/en/tools/easypic6/
' Oscillator: HS, 08.0000 MHz
' Ext. Modules: -
' SW: mikroBasic PRO for PIC
' http://www.mikroe.com/en/compilers/mikrobasic/pro/pic/
' * NOTES:
' - RX and TX UART switches on EasyPIC6 should be turned ON (SW7.1 and SW8.1).
' *
program UART
dim uart_rd as byte
main:
UART1_Init(9600) ' Initialize UART module at 9600 bps
Delay_ms(100) ' Wait for UART module to stabilize
UART1_Write_Text("Ready")
UART1_Write(10) ' Line Feed
UART1_Write(13) ' Carriage Return
while (TRUE) ' Endless loop
if (UART1_Data_Ready() <> 0) then ' If data is received,
uart_rd = UART1_Read() ' read the received data,
UART1_Write(uart_rd) ' and send data via UART
end if
wend
end.
Then I programmed my 18F4550 with the below PBP code that is an adaptation I got from Mackrackit. Although the code compiles and runs, the serial interface doesn't work....no character loopbacks to Hyperterminal when typed and an oscilloscope connection to the RX pin of the 18F4550 shows nothing when characters are typed into Hyperterminal.
I have studied the code in both cases and see little functional difference. Yet one works and the other doesn't.
Can anyone advise me what changes to make to the PBP code to get it to work??
Code:
'ASM ; 18F2550/4550, 8mhz crystal
' __CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC4_PLL6_1L & _USBDIV_2_1L
' __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
' __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
' __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
' __CONFIG _CONFIG3H, _PBADEN_OFF_3H ; PortB resets as digital
' __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
'ENDASM
Include "Modedefs.Bas"
DEFINE OSC 16
'Register Settings
RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $24 ' Enable transmit, BRGH = 1
SPBRG = 160 ' 9600 Baud @ 16MHz, -0.08%
SPBRGH = 1
' BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
TRISB = %00000000 ' Set PORTB to outputs as test LEDs
INCLUDE "ALLDIGITAL.pbp" ' Sets all registers for digital ops.
' User must make sure the AllDigital.pbp file
' is in same directory location as this source
' code before compiling.
PORTB = 0 ' Turn off the LEDs
HIGH PORTB.4 ' Blink the one Test LED as proof MCU is running
PAUSE 500
LOW PORTB.4
' Declare variables
X VAR BYTE
START:
RCSTA.4 = 0 : RCSTA.4 = 1
HSERIN [DEC X]
PORTB.5 = 1 ' Turn on PortB.6 LED if this statement is executed
' as test of receiving a character
HSEROUT [DEC X,$d,$a]
PORTB.6 =1 ' Turn on PortB.7 LED if this statement is executed
' as test of HSEROUT having sent a character
GOTO START
Bookmarks