Searching \ for '16f628 echo chars to pc' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=16F
Search entire site for: '16f628 echo chars to pc'.

Truncated match.
PICList Thread
'16f628 echo chars to pc'
2002\10\24@075803 by al

picon face
We were given this code and told it will echo characters back to a pc.
Told that it works.
Loaded into the pic built the hardware.Connected it to
pc serial port com1. Seems to run okay in simulation
(just have to trigger the recieved interupt manually).
Can measure characters getting sent to the
board by the computer but nothing is getting sent back.

Told the code works and if we get any problems that its most likely due to
using the internal clock.

So using external 4 MHz xtal. Clock is working fine, scope shows it nice and
clean.

Nothing is getting sent back to the pc.

Haven't used pics before.(first time for assembly) only used c before.
Not using leds on the portb outputs, not enough pins.

Logic probes connected to the other portb pins
getting outputs on the pin. Appear to
be correct partial bit patterns.

Whats wrong, I don't understand the way the addressing
appears to work.
Told the pic is very convoluted and is hard for beginners to understand.

Seems really weird compared to the avr and z80 chips.


All help greatly appreciated.

E

;
;***********************************************************
; PIC16f628 EXAMPLE CODE FOR a PIC usart ;
;
; FREQUENCY: 4MHz
;
;************************************************************
; This program demonstrates basic functionality of the USART.
;
; Port B is connected to 8 LEDs. //excluding the one the usart is on
; When the PIC16f628 receives a byte of data from
; the USART, the value is displayed on the LEDs and
; is retransmitted to the host computer.
;
; Set terminal program to 9600 baud, 1 stop bit, no parity
;
; Echos to a PC


list p=16f628 ; set processor type
list n=0  ; supress page breaks in list file
#include <P16f628.INC>
__CONFIG _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _WDT_OFF & _CP_OFF & _LVP_OFF &
_PWRTE_ON
;************************************************************
; Reset and Interrupt Vectors

org 0h ; Reset Vector
goto Start

org 4h ; Interrupt vector
goto IntVector

;************************************************************
; Program begins here

org 5h ; Beginning of program EPROM
Start movlw 0
BANKSEL TRISB
movlw b'00000110'
movwf TRISB  ;0=output  1=input
   ;!BUT for UART use RB1 and RB2 MUST be programmed as an INPUT!
BANKSEL PORTB
movwf PORTB ; Clear PORTB output latches


;  Now let us set the baud rate

BANKSEL SPBRG
movlw D'25'  ;'26' ; 9600 baud @4MHz
movwf 19h ; if we use SPBRG(ie 98h) instead of 19h, this assembler "spits
the dummy"
;   a bank zero address even though bank 1 is selected with RP0=1 works.

;  Now we must set up the type of transmission we want
; note we cannot use the TXSTA symbol sice the assembler does not like it
bsf 18h,TXEN ; Enable transmit
bsf 18h,BRGH ; Select high baud rate
BANKSEL RCSTA
bsf RCSTA,SPEN ; Enable Serial Port
bsf RCSTA,CREN ; Enable continuous reception

bcf PIR1,RCIF ; Clear RCIF Interrupt Flag

; These next other bits are in bank 1

BANKSEL PIE1
bsf 0ch,RCIE ; Set RCIE Interrupt Enable (its in bank 1)

; again have to use a bank zero address to make assembler work

bsf INTCON,PEIE ; Enable peripheral interrupts
bsf INTCON,GIE ; Enable global interrupts

BANKSEL RCREG
;-------Send Dummy Char to start UART ------------------
movf RCREG,w  ;clear uart receiver
movf RCREG,w  ; including fifo
movf RCREG,w  ; which is two deep.
movlw 0  ;any character will do.
movwf TXREG  ;send out dummy character
   ; to get transmit flag valid!

;************************************************************
; Main loop

Main
goto Main ; loop to self doing nothing

;************************************************************
; Interrupt Service Routine

IntVector
;  save context (WREG and STATUS registers) if needed in some real
application.

BANKSEL PIR1
btfss PIR1,RCIF ; Did USART cause interrupt?
goto OtherInt ; No, some other interrupt

movlw 06h  ; Mask out unwanted bits
andwf RCSTA,W  ; Check for errors
btfss STATUS,Z ; Was either error status bit set?
goto RcvError ; Found error, flag it

movf RCREG,W  ; Get input data

; movwf PORTB  ; Display on LEDs - note not enough pins on one port
;  we need to get some spare pins from bot ports A and port B to do this

movwf TXREG  ; Echo character back
goto ISREnd  ; go to end of ISR, restore context, return

RcvError
bcf RCSTA,CREN ; Clear receiver status
bsf RCSTA,CREN
movlw 0FFh  ; Light all LEDs
movwf PORTB
goto ISREnd ; go to end of ISR, restore context, return

OtherInt
; Find cause of interrupt and service it before returning from
  ; interrupt. If not, the same interrupt will re-occur as soon
  ; as execution returns to interrupted program.
retfie
ISREnd
; Restore context if needed in some real application.
retfie

end

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\10\24@180641 by Tony Nixon

flavicon
picon face
al wrote:
>
> We were given this code and told it will echo characters back to a pc.
> Told that it works.


Try this....

;
       Title "Simple serial"
;
       list P = 16F628
;
       include "P16f628.inc"
;
; ------------------
; CONFIGURATION FUSE
; ------------------
;
       __CONFIG _CP_OFF & _HS_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF &
_LVP_OFF & _MCLRE_ON
;
;
; -------------
; REGISTER LIST
; -------------
;
       CBLOCK 0x20

RxHold
DelayH
DelayL

       ENDC
;
; ---------------------
; YOUR CODE BEGINS HERE
; ---------------------
;
       org 0x0000


       clrf PORTA              ; assumes nothing connected to ports
       movlw b'00000100'       ; except serial port
         movwf PORTB
         bsf STATUS,RP0
         clrf TRISA
       movlw b'00000010'
         movwf TRISB
;
; ------------------------------------
; SET BAUD RATE TO COMMUNICATE WITH PC
; ------------------------------------
; Boot Baud Rate = 19200, No Parity, 1 Stop Bit
;
       bsf STATUS,RP0
       movlw 0x0C              ; 19200 baud
       movwf SPBRG
       movlw b'00100100'               ; brgh = high (2)
       movwf TXSTA             ; enable Async Transmission, set brgh
       movlw b'10010000'               ; enable Async Reception
       bcf STATUS,RP0
       movwf RCSTA
;
; -----------------------
; DISABLE THE COMPARATORS
; -----------------------
;
       movlw b'00000111'               ; disable comparators
       movwf CMCON

       call Del12mS


MainLoop        call Receive            ; wait for reception
       movwf TXREG             ; echo it back
       goto MainLoop

;
; ----------------------------
; RECEIVE CHARACTER FROM RS232
; ----------------------------
; This routine does not return until a character is received.

Receive   btfss PIR1,RCIF               ; (5) check for received data
         goto Receive

         movf RCREG,W
         return
;
; ----------
; 12mS Delay
; ----------
;
Del12mS   clrf DelayL
         movlw 11h
         movwf DelayH
InDel12   decfsz DelayL
         goto InDel12
         decfsz DelayH
         goto InDel12
         return

       ;
       ;
       end

--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
spam_OUTsalesTakeThisOuTspambubblesoftonline.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\10\26@225938 by elect phys

picon face
----- Original Message -----
From: "Tony Nixon" <.....tony.nixonKILLspamspam@spam@ENG.MONASH.EDU.AU>
To: <PICLISTspamKILLspamMITVMA.MIT.EDU>
Sent: Friday, October 25, 2002 9:04 AM
Subject: Re: 16f628 echo chars to pc


{Quote hidden}

Thanks for that.

Modified my orginal program.
Any suggestions on better ways or
cleaner code.

Also how do you use weak pull ups.
I am not clear on this, or how you set it.

All help greatly appreciated.
Thank you.
Al

;
;***********************************************************
; PIC16f628 EXAMPLE CODE FOR a PIC usart demo
;
;
; FREQUENCY: 4MHz
;
;************************************************************
; This program demonstrates basic functionality of the USART.
;
; Port B is connected to 8 LEDs. //excluding the one the usart is on
; When the PIC16f628 receives a byte of data from
; the USART, the value is displayed on the LEDs and
; is retransmitted to the host computer.
;
; Set terminal program to 9600 baud, 1 stop bit, no parity
;
; Get this working show it Echo'ing to a PC, then make it do something
usefull


list p=16f628 ; set processor type
list n=0  ; supress page breaks in list file

#include <P16f628.INC>
__CONFIG _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _WDT_OFF & _CP_OFF & _LVP_OFF &
_PWRTE_ON
;************************************************************
; Reset and Interrupt Vectors

org 0h ; Reset Vector
goto Start

org 4h ; Interrupt vector
goto IntVector

;************************************************************
; Program begins here

org 5h ; Beginning of program EPROM
Start movlw 0
BANKSEL TRISB
movlw b'00000110'
movwf TRISB  ;0=output  1=input
   ;!BUT for UART use RB1 and RB2 MUST be programmed as an INPUT!
BANKSEL PORTB
movwf PORTB ; Clear PORTB output latches

movlw 0
BANKSEL TRISA
movlw b'00000000'
movwf TRISA

BANKSEL PORTA
movwf PORTA

;  Now let us set the baud rate

BANKSEL SPBRG
movlw D'25' ; 9600 baud @4MHz
movwf SPBRG ;
;  Now we must set up the type of transmission we want

BANKSEL TXSTA
movlw b'00100100' ;Transmit enabled and high baud rate selected
movwf TXSTA

BANKSEL RCSTA
movlw b'10010000' ;Serial port enabled and continuous recieve enabled
movwf RCSTA

BANKSEL PIR1
bcf PIR1,RCIF ;Recieve interrupt flag cleared

BANKSEL PIE1
bsf PIE1,RCIE ;recieve interrupt enabled

BANKSEL INTCON
bsf INTCON,PEIE ;Peripheral interrupt enabled
bsf INTCON,GIE ;Global interrupt enabled



BANKSEL RCREG
;-------Send Dummy Char to start UART (must do ..alex)------------------
movf RCREG,W  ;clear uart receiver
movf RCREG,W  ; including fifo
movf RCREG,W  ; which is two deep.
movlw 0  ;any character will do.
movwf TXREG  ;send out dummy character
   ; to get transmit flag valid!

;************************************************************
; Main loop

Main
goto Main ; loop to self doing nothing

;************************************************************
; Interrupt Service Routine

IntVector
;  save context (WREG and STATUS registers) if needed in some real
application.

BANKSEL PIR1
btfss PIR1,RCIF ; Did USART cause interrupt?
goto OtherInt ; No, some other interrupt

bcf PIR1,RCIF
movlw 06h  ; Mask out unwanted bits
andwf RCSTA,W  ; Check for errors
btfss STATUS,Z ; Was either error status bit set?
goto RcvError ; Found error, flag it

movf RCREG,W  ; Get input data

movwf PORTA  ; Display on LEDs - note not enough pins on one port
;  we need to get some spare pins from bot ports A and port B to do this
(changed to A)

movwf TXREG  ; Echo character back
goto ISREnd  ; go to end of ISR, restore context, return

RcvError
bcf RCSTA,CREN ; Clear receiver status
bsf RCSTA,CREN
movlw 0FFh  ; Light all LEDs
movwf PORTB
goto ISREnd ; go to end of ISR, restore context, return

OtherInt
; Find cause of interrupt and service it before returning from
  ; interrupt. If not, the same interrupt will re-occur as soon
  ; as execution returns to interrupted program.
retfie
ISREnd
; Restore context if needed in some real application.
retfie

end

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...