USART serial comms on 16f688 problems

Status
Not open for further replies.
I'm using the 16F688 pic, I've got it to flash an led on and off, wait for a button to be pressed before running some code, but I haven't been able to get it to talk to my PC yet. My code is attached, can anyone see anything obviously wrong with it - it's probably something simple I'm forgetting. Also I'm using the PicKit1 kit with the serial part populated with a max 232 etc, if that helps.

Thanks

Code:
;**********************************************************************
;   This file is a basic code template for object module code         *
;   generation on the PICmicro PIC16F688. This file contains the      *
;   basic code building blocks to build upon.  As a project minimum   *
;   the 16F688.lkr file will also be required for this file to        *
;   correctly build. The .lkr files are located in the MPLAB          *
;   directory.                                                        *
;                                                                     *
;   If interrupts are not used all code presented between the         *
;   code section "INT_VECTOR and code section "MAIN" can be removed.  *
;   In addition the variable assignments for 'w_temp' and             *
;   'status_temp' can be removed.                                     *
;                                                                     *
;   If interrupts are used, as in this template file, the 16F688.lkr  *
;   file will need to be modified as follows: Remove the lines        *
;     CODEPAGE   NAME=vectors  START=0x0      END=0x4      PROTECTED  *
;   and                                                               *
;     SECTION    NAME=STARTUP  ROM=vectors                            *
;   and change the start address of the page0 section from 0x5 to 0x0 *
;                                                                     *
;   Refer to the MPASM User's Guide for additional information on     *
;   features of the assembler and linker (Document DS33014).          *
;                                                                     *
;   Refer to the respective PICmicro data sheet for additional        *
;   information on the instruction set.                               *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Filename: Flashing LED1.asm                                      *
;    Date: 2009/04/20                                                 *
;    File Version: 1.0                                                *
;                                                                     *
;    Author: Jules Lewarne                                            *
;    Company:                                                         *
;                                                                     *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Files required:                                                  *
;                    16F688.lkr                                       *
;                                                                     *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Notes:                                                           *
;                                                                     *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************

	list      p=16F688           	; list directive to define processor
	#include <p16F688.inc>        	; processor specific variable definitions

	errorlevel  -302              	; suppress message 302 from list file

; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.

	__CONFIG    _CP_OFF & _CPD_OFF & _BOD_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _FCMEN_OFF & _IESO_OFF



;***** VARIABLE DEFINITIONS 

; FORMAT: [name]	RES	[number of bytes reserved]
INT_VAR		UDATA_SHR	0x71   
DVAR	RES 1
DVAR2	RES 1
DVAR3	RES 1

;**********************************************************************
RESET_VECTOR	CODE	0x000		; processor reset vector
		goto    Main            ; go to beginning of program


INT_VECTOR	CODE	0x004		; interrupt vector location
		retfie                  ; return from interrupt

;**********************************************************************
;	Function Name: MAIN
;	
;	Parameters:
;
;	Description: This is the main program which is executed once the processor
;		has powered up.
;		The code within this routine performs some device initialisation then
;		flashes an LED. This routine makes use of another routine which causes
;		a short delay by sending the prcessor into a loop which decrements from
;		an arbitrary value until it reaches zero.
;**********************************************************************

Main
		
		;		
		
		
		;Device Initialisation
		
        bsf     STATUS,RP0  ; set file register bank to 1
        clrf    ANSEL       ; switch off analog-to-digital conversation system (analog inputs : off) 
        
        movlw   B'11001111' ; Set Ports to I/O, TRISA register: [X][X][RA5][RA4][RA3][RA2][RA1][RA0]
        movwf   TRISA    	;									Don't  I/O	I/O	  I	  I/O  I/O  I/O
							;									Care    
							
		
        bcf     STATUS,RP0  ; set file register bank to 0

        movlw   B'00000111' ; switch off the comparator, enable digital i/o
        movwf   CMCON0      ;
		clrf	ADCON0		; switch off ADC module
		bcf		PORTA, 5
		
		clrf PORTA ; Set all PORTA outputs to zero
		bsf		TXSTA,5
		bcf		TXSTA,4
		bsf		TXSTA,2
		bsf		RCSTA,7
		bcf		BAUDCTL,3
		movlw	B'00011001' ; setup baudrate generator
		movwf	SPBRG

Loop  
		;btfsc PORTA,3 ; Wait for button on RA3
        ;goto Loop

				; PORTA register: [X][X][RA5][RA4][RA3][RA2][RA1][RA0]
     			;				   Don't  I/O	I/O	  I	  I/O  I/O  I/O
				;				   Care    
				;						   D0/D1   D2/D3  D6/D7
				;						  o-!>!-o---!>!--o-!>!-o
				;						  o-!<!-o---!<!--o-!<!-o
				;							   D4/D5
				;						  o-----!>!------o
				;						  o-----!<!------o


		;movlw B'00010000' ; PORTA Register
		;movwf PORTA

	
		bsf 	PORTA,4
		call 	Delay
		bcf 	PORTA,4 ; set BIT 4 of PORTA to zero
		call 	Delay
		
		movlw	B'01000001' ; = 'A' in ASCII
		movwf	TXREG
		
		
		
Goto Loop
;**********************************************************************************
Delay
    	movlw		0xff	; set outer delay loop (change these hex number to change the frequency)
    	movwf		DVAR2	; memory location
Delay0
    	movlw		0xff	; set inner delay loop  (change these hex number to change the frequency)
    	movwf		DVAR	; incremental memory
 							; location
Delay1	decfsz		DVAR,1
		goto		Delay1
    	decfsz		DVAR2,1
    	goto		Delay0
		
    	return



; initialize eeprom locations

EE		CODE	0x2100
		DE	0x00, 0x01, 0x02, 0x03


		END                       ; directive 'end of program'
 
Last edited:
I'm pretty sure one of the asm lads can point you in the right direction.

It could be as easy as a config issue given how small-a-program it is
 
You appear to have it setup for 2400 baud but it is quite hard to follow the rest of the code as you have used numbers.

Can I suggest you change things like,
Code:
	bcf	BAUDCTL,3
To,
Code:
	bcf	BAUDCTL,BRG16
This will make it easier to work out what you are doing.

Mike.
 
From what I see, the actual setup should be for 9600 bauds @4MHz.

Looks like an hardware problem to me, I would suggest to scope your signal, at the PIC output, then at your MAX232 output.
 
Working now, changed the numbers to named parameter - much easier to see what's going on. The problem was in the hardware, tx and rx were reversed, just that simple! Thanks
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…