Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

UART test with pic16f628a

Status
Not open for further replies.

dragonfighter

New Member
Hello all!

I took Lars Petersen's code and tried to program my pic.
The code sends alive message, then echoes characters at 9600 bps.

The code is compiled to hex by MPLAB IDE.
The problem is that some errors appear when I try to program the code using WinPIC or IC-Prog.

I don't think that it is a hardware issue as winpic initializes my pic succesfully and the interface test works.
WinPic Error log

Info: Loading definitions for "PIC16F628A" from devices.ini .
Info: PIC16F628A added by Leonardo, different device ID,
Info: and different 'Bulk Erase' procedure than 16F628 !
Parsed "C:\Program Files\Microchip\MPLAB IDE\Device\PIC16F628A.dev" : found 22 bit combinations in 8 configuration bit groups .
Initialising PIC-Programmer: Success.
Testing: delay(500ms) took 0.50 seconds, timer_freq=3006.8800 MHz ... ok
Programming...
Erasing ("bulk" or "chip") ...
Programming CODE, 0x000000..0x000042
Verifying 0x000000..0x000042
Verify Error: 000000: read 003FFF, wanted 003007
Verify Error: 000001: read 003FFF, wanted 00009F
Verify Error: 000002: read 003FFF, wanted 003000
Verify Error: 000003: read 003FFF, wanted 000085
More Verify Errors, unable to list all (total=67)
Programming CONFIG, 0x002000..0x002008
Verifying 0x002000..0x002007
Verify Error: 002007: read 003FFF, wanted 003F50
Programming CONFIG-WORD
Verifying 0x002007..0x002007
Verify Error: 002007: read 003FFF, wanted 003F50
ERROR: Programming FAILED !

UART TEST CODE

LIST P=16F628A, R=DEC ; Use the PIC16F628A and decimal system
processor 16F628A
#include <P16F628A.INC> ; Include header file

__config _INTOSC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_OFF & _BODEN_ON & _MCLRE_OFF & _CP_OFF
;
CBLOCK 0x20 ; Declare variable addresses starting at 0x20
dataL
ENDC
;
; --------------------------------
; SET ANALOG/DIGITAL INPUTS PORT A
; --------------------------------
;
movlw 7
movwf CMCON ; CMCON=7 set comperators off
;
; ----------------
; INITIALIZE PORTS
; ----------------
;
movlw b'00000000' ; set up portA
movwf PORTA

movlw b'00000100' ; RB2(TX)=1 others are 0
movwf PORTB

bsf STATUS,RP0 ; RAM PAGE 1

movlw 0xFF
movwf TRISA ; portA all pins input

movlw b'11110010' ; RB7-RB4 and RB1(RX)=input, others output
movwf TRISB

; ------------------------------------
; SET BAUD RATE TO COMMUNICATE WITH PC
; ------------------------------------
; Boot Baud Rate = 9600, No Parity, 1 Stop Bit
;
movlw 0x19 ; 0x19=9600 bps (0x0C=19200 bps)
movwf SPBRG
movlw b'00100100' ; brgh = high (2)
movwf TXSTA ; enable Async Transmission, set brgh

bcf STATUS,RP0 ; RAM PAGE 0

movlw b'10010000' ; enable Async Reception
movwf RCSTA
;
; ------------------------------------
; PROVIDE A SETTLING TIME FOR START UP
; ------------------------------------
;
clrf dataL
settle decfsz dataL,F
goto settle

movf RCREG,W
movf RCREG,W
movf RCREG,W ; flush receive buffer
;
; ---------
; MAIN LOOP
; ---------
;
call message ; send "16F628 alive"
loop call receive ; wait for a char
call send ; send the char
goto loop
;
; -------------------------------------------
; RECEIVE CHARACTER FROM RS232 AND STORE IN W
; -------------------------------------------
; This routine does not return until a character is received.
;
receive btfss PIR1,RCIF ; (5) check for received data
goto receive

movf RCREG,W ; save received data in W
return
;
; -------------------------------------------------------------
; SEND CHARACTER IN W VIA RS232 AND WAIT UNTIL FINISHED SENDING
; -------------------------------------------------------------
;
send movwf TXREG ; send data in W

TransWt bsf STATUS,RP0 ; RAM PAGE 1
WtHere btfss TXSTA,TRMT ; (1) transmission is complete if hi
goto WtHere

bcf STATUS,RP0 ; RAM PAGE 0
return
;
; -------
; MESSAGE
; -------
;
message movlw '1'
call send
movlw '6'
call send
movlw 'F'
call send
movlw '6'
call send
movlw '2'
call send
movlw '8'
call send
movlw ' '
call send
movlw 'a'
call send
movlw 'l'
call send
movlw 'i'
call send
movlw 'v'
call send
movlw 'e'
call send
movlw 0x0D ; CR
call send
movlw 0x0A ; LF
call send
return

END

PLEASE HELP!!
 
Last edited:
dragonfighter said:
I don't think that it is a hardware issue as winpic initializes my pic succesfully and the interface test works.

I'm most certain that is a hardware issue. All 67(address 0..0x42) of your data words were not programmed into the PIC.

Do a READ operation and confirm you can read the Device ID of 16F628A, which is "01 0000 011# ####", i.e. 0x106? or 0x107? where # can be 0 or 1 and ?=0-F.

Remember you'll need to pulldown the PGM pin(pin10) even though you are using HV programming.
 
Looks at the following image, if your programmer works then you should also get the device id as I have got.

The problem with serial port programmer is that they might not work and it depends solely on the hardware of the serial port on your PC or Laptop. Serial COM port on very old PC usually works but most laptop COM port won't.

To check, do a READ operation without the PIC and measure voltage across capacitor C1. You should get about 12~13V. If not, then there is no chance for it to work and you have to try those schematic that use separate power supply.
 

Attachments

  • winpic_628a.png
    winpic_628a.png
    10 KB · Views: 677
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top