• 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.

more questions about asm code

Status
Not open for further replies.

wejos

Member
this project should turn 8 leds on/off according to the binary value the user pressed in his keyboard. my problem is the schematic diagram for this project isn't available. i have no idea where RA2 was connected to which pin of MAX232. it says in the code that it wont continue unless pin 18 goes (im not sure if "btfsc" waits for high or low) so ill just say it's status have had changed.

Code:
switch	btfsc	portA, 2	; Is A2 equal 0? i.e. is switch closed?
; 	goto	switch		; No, so keep checking
second problem is im not sure if MAX232 is okay to use since the author said in the tutorial that a MAX233 was used. maybe this is where all the problem started. I used MAX232 as replacement of MAX233.

the entire code:

Code:
; FILE: rcv1_1.asm
; AUTH: P.Oh
; DATE: 04/27/02 18:00 1.0 - WORKS
;	04/27/02 18:35 1.1
; DESC: 1.0: PC-to-PIC serial communications.  LEDs display binary equivalent
;            of key typed on PC
;       1.1: Same as 1.0 but eliminates need for switch
; REFS: rcv4800.asm in PIC'n Techniques p. 219

;--------------------------------------------------------------------------
	list	p=16f84
	radix	hex
;--------------------------------------------------------------------------
; 	CPU EQUATES

tmr0	equ	0x01	; Timer/counter register
status	equ	0x03	; Status word register. See Easy PIC'n p. 145
portA	equ	0x05	; Port A register
portB	equ	0x06	; Port B register
intCon	equ	0x0b	; Interrupt control register
rcvReg	equ	0x0c	; General purpose register
count	equ	0x0d	; General purpose register
temp	equ	0x0e	; General purpose register
optReg	equ	0x81	; File register in Bank 1
trisA	equ	0x85	; File register in Bank 1. See Easy PIC'n p. 145
trisB	equ	0x86	; File register in Bank 1. See Easy PIC'n p. 145
;--------------------------------------------------------------------------
; 	BIT EQUATES
rp0	equ	5
;--------------------------------------------------------------------------
	org	0x000

start	bsf 	status, rp0	; Switch to Bank 1. See Easy PIC'n p. 145
	movlw	b'00000101'	; A0, A2 are input and the rest are output
	movwf	trisA
	movlw	b'00000000'	; Port B: all output
	movwf	trisB
	bcf	status, rp0	; Switch back to Bank 0
	clrf	portB
	clrf	rcvReg
; switch	btfsc	portA, 2	; Is A2 equal 0? i.e. is switch closed?
; 	goto	switch		; No, so keep checking
doThis	call	rcv4800		; Yes, to serial in subroutine
	movf	rcvReg,  w	; Get byte received
	movwf	portB		; Display byte on the 8 LEDs
circle	goto	doThis		; Done
;--------------------------------------------------------------------------
rcv4800	bcf	intCon, 5	; Disable tmr0 interrupts
	bcf	intCon,	7	; Disable global interrupts
	clrf	tmr0		; Clear timer/counter
	clrwdt			; Clear wdt prep prescaler assign
	bsf	status, rp0	; to page 1	
	movlw	b'11011000'	; set up timer/counter
	movwf	optReg
	bcf	status, rp0	; Back to page 1
	movlw	0x08		; Init shift counter
	movwf	count
sbit	btfsc	portA, 0	; Look for start bit
	goto 	sbit		; For Mark
	movlw	0x98		; 
	movwf	tmr0		; Load and start timer/counter
	bcf	intCon, 2	; Clear tmr0 overflow flag
time1	btfss	intCon, 2	; Has the timer (bit 2) overflowed?  Skip next line if 1
	goto	time1		; No
	btfsc	portA, 0	; Start bit still low?
	goto 	sbit		; False start, go back
	movlw	0x30		; real, define N for timer
	movwf	tmr0		; start timer/counter - bit time
	bcf	intCon, 2	; Clear tmr0 overflow flag
time2	btfss	intCon, 2	; Timer overflow?
	goto	time2		; No
	movlw	0x30		; Yes, define N for timer
	movwf	tmr0		; Start timer/counter
	bcf	intCon, 2;	; Clear tmr0 overflow flah
	movf	portA, w	; Read port A
	movwf	temp		; Store
	rrf	temp, f		; Rotate bit 0 into carry flag
	rrf	rcvReg, f	; Rotate carry into rcvReg bit 7
	decfsz	count, f	; Shifted 8?
	goto	time2		; No
time3	btfss	intCon, 2	; Timer overflow?
	goto	time3		; No
	return			; Yes, byte received
;-----------------------------------------------------------------------
	end
;-----------------------------------------------------------------------
; At blast time, select:
; 	memory unprotected
; 	watchdog timer disabled
;	standard crystal (4 MHz)
; 	power-up timer on
;=======================================================================

after this im heading for nigel's work...
 

Pommie

Well-Known Member
Most Helpful Member
That code expects to receive a byte on RA0 and so one of the MAX232 TTL outputs should connect to RA0.

If I was you I would ignore that code and head straight for Nigel's tutorials.

Mike.
 

AtomSoft

Well-Known Member
btfsc = Bit Test F Skip if Clear
hence it waits for a 0 aka LOW which means RA2 should be pulled high via resistor.

what PIC are you using?
 

be80be

Well-Known Member
Nigels Tutorial Would be a walk in the park to use with the 16F84 all you change is the
chip from 16F628 to 16F84 and the fuse setting or config which one you wait to call it. Like this you would change this part
Code:
	LIST	p=16F628		;tell assembler what chip we are using
	include "P16F628.inc"		;include the defaults for the chip
	ERRORLEVEL	0,	-302	;suppress bank selection messages
	__config 0x3D18			;sets the configuration settings (oscillator type etc.)
To this
Code:
	LIST	p=16F84		;tell assembler what chip we are using
	include "P16F84.inc"		;include the defaults for the chip
	ERRORLEVEL	0,	-302	;suppress bank selection messages
	__CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _HS_OSC ;sets the configuration settings (oscillator type etc.) or RC_OSC if thats what your using
And this part
Code:
movlw	0x07
movwf	CMCON	;turn comparators off (make it like a 16F84) remove it  you don't need it
 

wejos

Member
AtomSoft im using 16f84. what do you mean by pulled high via resistor?

b80be, i think i have used TX since its caps are 10pf (should they be 33pf?)

so should i replace "_HS_OSC" with what???

a "_TX_OSC" ?

i apologize for the 20 questions guys, you're dealing with a super newbie here.

I was hoping to make these two work (nigel's and the first code).

tumbling down the rabbit hole hehe
 

be80be

Well-Known Member
Here alist of the config bits
;==========================================================================
;
; Configuration Bits
;
;==========================================================================

_CP_ON EQU H'000F'
_CP_OFF EQU H'3FFF'
_PWRTE_ON EQU H'3FF7'
_PWRTE_OFF EQU H'3FFF'
_WDT_ON EQU H'3FFF'
_WDT_OFF EQU H'3FFB'
_LP_OSC EQU H'3FFC'
_XT_OSC EQU H'3FFD'
_HS_OSC EQU H'3FFE'
_RC_OSC EQU H'3FFF'
This tells you which one to use
6.2 Oscillator Configurations
6.2.1 OSCILLATOR TYPES
The PIC16F84A can be operated in four different
oscillator modes. The user can program two
configuration bits (FOSC1 and FOSC0) to select one of
these four modes:
• LP Low Power Crystal
• XT Crystal/Resonator
• HS High Speed Crystal/Resonator
• RC Resistor/Capacitor
6.2.2 CRYSTAL OSCILLATOR/CERAMIC
RESONATORS
In XT, LP, or HS modes, a crystal or ceramic resonator
is connected to the OSC1/CLKIN and OSC2/CLKOUT
pins to establish oscillation (Figure 6-1).
 
Last edited:

wejos

Member
appreciate it be80be for posting the info when i shouldve googled them myself. saved me time. i owe you guys
 

be80be

Well-Known Member
Why would you want a switch in there when all that code is to make a leds show you the binary equivalent of what you pressed on your keyboard
 

wejos

Member
i have no idea why theres a switch there. heres my source for that. the schematics are all gone. the url link is wrong but i removed the wrong part still no schematic in the index.

PIC16F84 Fundamentals

you think i can skip the "switch" part?

Atom, i've downloaded it. looks like i need a adobe reader. ill install one after i looked for the cds here somewhere. ty you guys have been a good help really. you guys have been good to me, be80be, Atom.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top