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.

Total Newbie Just Need a Push in The Right Direction

Status
Not open for further replies.
Hello,

Looking at the titles of some of the other posts here I feel a little out of my depth, but what the hell. Here's an easy problem for you to solve for once.

Right, im doing a project at Uni, we've been told we need to program a PIC as part of this project, which sounds a bit harsh to me as we haven't had any lectures on it and aren't due to before the hand in date.

So im trying to learn how they work along with getting my head around BASIC. I bought a PIC programmer VM111/K8048. It came with PIC16F627 I can get the basic demos to work, but as soon as I try anything of my own it all fails. I found a basic flashing LED program that was written for the 16F627, so I thought i'd give it a go, but can't for the life of me get the thing to work, here's the code,

LIST P=PIC16F627
INCLUDE C:\PicProg2009\Include\P16F627.inc

LOOP EQU 0x20

init BSF STATUS, RP0
BCF PCON, OSCF
MOVLW 0x00
MOVWF TRISB
BCF STATUS, RP0

LED_on BSF PORTB, 0

delay_1 DECFSZ LOOP, 1
GOTO delay_1

LED_off BCF PORTB, 0

delay_2 DECFSZ LOOP, 1
GOTO delay_2

GOTO LED_on

END

Sorry about the format, I assure you the spaces are in the correct place in my notepad file. From the datasheet the oscillator is at 37Khz, I did try adding some additional loops to keep the led on and off for longer but all I ever get is permanent ON LED. So I added this in place of LED_on and delay_1

LED_on BSF PORTB,0
MOVLW 0xFF
MOVWF LOOP

delay_1 DECFSZ LOOP,1
GOTO delay_1
MOVLW 0xFF
MOVWF LOOP
A1 DECFSZ LOOP,1
GOTO A1
MOVLW 0xFF
MOVWF LOOP
A2 DECFSZ LOOP,1
GOTO A2

I also added this to delay_2 but this made no difference, no matter how many times I add the loop the LED remains on. I just need some kind of foothold so I know what the hell is going on then I can build from there but at the moment nothing makes any sense.

Thanks for any help you can give me, even if it's just a slap round the head.
 
Last edited:
Hello,

Looking at the titles of some of the other posts here I feel a little out of my depth, but what the hell. Here's an easy problem for you to solve for once.

Right, im doing a project at Uni, we've been told we need to program a PIC as part of this project, which sounds a bit harsh to me as we haven't had any lectures on it and aren't due to before the hand in date.

So im trying to learn how they work along with getting my head around BASIC. I bought a PIC programmer VM111/K8048. It came with PIC16F627 I can get the basic demos to work, but as soon as I try anything of my own it all fails. I found a basic flashing LED program that was written for the 16F627, so I thought i'd give it a go, but can't for the life of me get the thing to work, here's the code,

LIST P=PIC16F627
INCLUDE C:\PicProg2009\Include\P16F627.inc

LOOP EQU 0x20

init BSF STATUS, RP0
BCF PCON, OSCF
MOVLW 0x00
MOVWF TRISB
BCF STATUS, RP0

LED_on BSF PORTB, 0

delay_1 DECFSZ LOOP, 1
GOTO delay_1

LED_off BCF PORTB, 0

delay_2 DECFSZ LOOP, 1
GOTO delay_2

GOTO LED_on

END

Sorry about the format, I assure you the spaces are in the correct place in my notepad file. From the datasheet the oscillator is at 37Khz, I did try adding some additional loops to keep the led on and off for longer but all I ever get is permanent ON LED. So I added this in place of LED_on and delay_1

LED_on BSF PORTB,0
MOVLW 0xFF
MOVWF LOOP

delay_1 DECFSZ LOOP,1
GOTO delay_1
MOVLW 0xFF
MOVWF LOOP
A1 DECFSZ LOOP,1
GOTO A1
MOVLW 0xFF
MOVWF LOOP
A2 DECFSZ LOOP,1
GOTO A2

I also added this to delay_2 but this made no difference, no matter how many times I add the loop the LED remains on. I just need some kind of foothold so I know what the hell is going on then I can build from there but at the moment nothing makes any sense.

Thanks for any help you can give me, even if it's just a slap round the head.

For one you forgot the config word in the header of your source code. This tells the chip whether you want this list of features enabled or disabled -

Code Protection
Data Code Protection
MCLR Pin
Power Up Timer
Watchdog Timer
Brownout Detection
Low Voltage Programming

It also sets it up for the oscillator type. What type of oscillator are you using? Internal RC? External RC? Crystal? If you're using a crystal what frequency is the crystal rated for?

Second off...assembly instructions are typed in lower case.

Third...delays are usually canned as subroutines since they're a task that has to get carried out over and over. This way you only have to type the code for the delay once, then use a "call" instruction to jump the program counter to the subroutine. The catch is that it has to have a "return" instruction after the subroutine in order for the program counter to return back to where it left off in the main program.

Furthermore, at fast oscillator speeds you'll more than likely have to run a nested delay loop, which is basically a second file register that gets decrimented everytime the first register decriments from 0xFF to 0x00 (255 - 0). This sets it up with longer delays.

Also, when you designate the processor, you don't list the processor type as PIC16F627. You just list it as 16F627. The assembler will generate an error message if you try to assemble it with PIC16F627 in the list directive.

Here is your code re-written without the configuration word -

Code:
		list 		 p=16F627
		include		 <16F627.inc>

		__config	_CP_OFF & DATA_CP_OFF & _LVP_OFF & _BODEN_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT

;No code protection (_CP_OFF)
;No data code protection (_DATA_CP_OFF)
;Low Voltage Programming off (_LVP_OFF)
;Brown Out Detection Off (_BODEN_OFF)
;Master Reset pin active (_MCLRE_ON)
;Power Up Timer on (_PWRTE_ON)
;Watchdog Timer off (_WDT_OFF)
;Internal RC oscillator (_INTRC_OSC_NOCLKOUT)

LOOP 		EQU		 0x20			;label address 0x20 with LOOP

init		bsf		STATUS, RP0		;change to Bank 1		
		bcf		PCON, OSCF		;set internal oscillator frequency to 37kHz
		movlw		0x00			;set Port A as all outputs
		movwf		TRISA
		movlw		0x00			;set Port B as all outputs
		movwf		TRISB
		bcf		STATUS,RP0		;change to Bank 0

LED_on		bsf		PORTB, 0		;turn on LED

		call		delay_1			;wait

LED_off 	bcf		PORTB, 0		;turn off LED

		call		delay_1			;wait

		goto		LED_on			;do it again

delay_1	 	movlw		0xFF			;start delay counter at 255
		movwf		LOOP		
W8		decfsz		LOOP, 1			;decriment delay counter, branch if zero
		goto		W8			;go back
		return					;return from subroutine
		
		end

If you can tell me what oscillator type you're using (and the frequency if it's a crystal oscillator) I can show you how to write the configuration word for your source code file.

EDIT: I just realized you set the internal oscillator frequency to 37kHz so I'm assuming you're using the chip's internal oscillator. If you're using a 4MHz crystal oscillator, change _INTRC_OSC_NOCLKOUT in the configuration word to _XT_OSC (Standard Crystal Oscillator). If you're using a crystal oscillator that is greater than 4MHz, change _INTRC_OSC_NOCLKOUT in the configuration word to _HS_OSC (High Speed Crystal Oscillator).

One more thing...when you write the configuration word, the instruction __config is TWO underscores preceeding "config". All of the configuration words proceeding __config are all single underscore.
 
Last edited:
Your mixing asm with basic don't work asm is like this I borrowed this from Nigel web site and redid it for 16f627
should work but look it over you can see how you should code asm It's well committed
Code:
 list      p=16f627            ; list directive to define processor
	#include <p16f627.inc>        ; processor specific variable definitions
	
	__CONFIG _CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & __INTRC_OSC_NOCLKOUT & _MCLRE_ON & _LVP_ON
	
	cblock 	0x20 			;start of general purpose registers
		count1 			;used in delay routine
		counta 			;used in delay routine 
		countb 			;used in delay routine
	endc
	
	org	0x0000			;org sets the origin, 0x0000 for the 16F628,
					;this is where the program starts running	
	movlw	0x07
	movwf	CMCON			;turn comparators off (make it like a 16F84)

   	bsf 	STATUS,		RP0	;select bank 1
   	movlw 	b'00000000'		;set PortB all outputs
   	movwf 	TRISB
	movwf	TRISA			;set PortA all outputs
	bcf	STATUS,		RP0	;select bank 0

Loop	
	movlw	0xff
	movwf	PORTA			;set all bits on
	movwf	PORTB
	nop				;the nop's make up the time taken by the goto
	nop				;giving a square wave output
	call	Delay			;this waits for a while!
	movlw	0x00
	movwf	PORTA
	movwf	PORTB			;set all bits off
	call	Delay
	goto	Loop			;go back and do it again

Delay	movlw	d'250'			;delay 250 ms (4 MHz clock)
	movwf	count1
d1	movlw	0xC7
	movwf	counta
	movlw	0x01
	movwf	countb
Delay_0
	decfsz	counta, f
	goto	$+2
	decfsz	countb, f
	goto	Delay_0

	decfsz	count1	,f
	goto	d1
	retlw	0x00

	end

Oh and use code tags
 
Last edited:
All his code did was turn on the led and then go and set in the delay If it would of compiled

Your programmer came with nice code examples

Code:
 DELAY_ROUTINE   MOVLW   D'100'         ;54 Generate approx 10mS delay at 4Mhz CLK
                MOVWF   TIMER2
DEL_LOOP1       MOVLW   D'100'	       ;60	
                MOVWF   TIMER1
DEL_LOOP2       BTFSC	PORTA,SW1
		GOTO	MENU
		BTFSC	PORTA,SW2
		GOTO	MENU
		BTFSC	PORTA,SW3
		GOTO	MENU
		BTFSC	PORTA,SW4
		GOTO	MENU
		DECFSZ  TIMER1,F
                GOTO    DEL_LOOP2
                DECFSZ  TIMER2,F
                GOTO    DEL_LOOP1
		RETLW   0

Thats the delay example from VELLEMAN High-Q KIT K8048/VM111 SAMPLE SOFTWARE

Down load Mplab you'll like it **broken link removed**
 
Ok, thanks for the replies. I'll start at the top.

I tried the code you posted and it worked, thank god for that. Looks like it was that config line that did it. There are tick boxes, in the PIC programming program that I use, related to all those options I thought that ticking/unticking those boxes sorted the options out, apparently not. By writing the config line the options were automatically changed in the program (Boxes ticked/unticked etc) to what the config line specified.

I will be using the internal oscillator for my project, seems much easier, I think i'm right in saying at 37khz the PIC will run at 37k/4 instructions per second, so just under 9000 a second which is more than quick enough.

As for the second guy, your code worked as well so thanks. Im not sure what you mean when you said im mixing BASIC with asm, I thought it was all in BASIC. The demo programs were fine but honestly im starting from scratch, it's only just now that im starting to have any understanding of how the code works.

I do have another question that will help me with my project,

In my project I will use 1 input on the PIC, that input will receive 4 identical signals each lasting a different length of time, so,

Signal 1 = 1sec
Signal 2 = 2sec
Signal 3 = 3sec
Signal 4 = 4sec

I need to be able to differentiate between the 4 signals. I was going to set a counter that counts for as long as the signal is active and then compares the final number with 4 preset ranges, so for example say the counter counts to 10 per second

Signal 1 = 1sec range between 0 and 15
Signal 2 = 2sec range between 16 and 25
Signal 3 = 3sec range between 26 and 35
Signal 4 = 4sec range between 36 and 45

The reason I wanted to use ranges instead of exact numbers is because i'm very doubtful the numbers will be exactly the same every time, so if I counted a number of say 22, how would i compare 22 to the 4 different ranges to determine which range it fell in?

Thanks a lot for your help so far.
 
Tell me something are you using note pad and compiling on the command line with
 

Attachments

  • this1.PNG
    this1.PNG
    27.9 KB · Views: 274
Yes that's exactly what im doing. I have looked at MPLAB IDE and code composer and about a million other programs, but to be honest, I want to keep it simple at first, using big complicated programs with loads of options just makes it more likely that there's going to be some kind of mistake, by me of course.
 
Well your your coding in assembly. What I meant Is your code looked like your trying to use basic style sintexts

Assembly is like this
Code:
blink_leds:      ; this is a label 
      ;your code goes here

  goto blink_leds ;you will just sit in this loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Delay you want to return back where it was called 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

Loop:	; I like this style of naming easy to read
	movlw	0xff
	movwf	PORTA			;set all bits on
	movwf	PORTB
	nop				;the nop's make up the time taken by the goto
	nop				;giving a square wave output
	call	Delay			;this waits for a while!
	movlw	0x00
	movwf	PORTA
	movwf	PORTB			;set all bits off
	call	Delay
	goto	Loop			;go back and do it again

Delay:	
        movlw	d'250'			;delay 250 ms (4 MHz clock)
D1:
	movlw	0xC7
	movwf	counta
	movlw	0x01
	movwf	countb
Delay_0:
	decfsz	counta, f
	goto	$+2
	decfsz	countb, f
	goto	Delay_0

	decfsz	count1	,f
	goto	d1
	retlw	0x00

	end

There a lot of ways to compare numbers

Here a sample to compare ADC values
Code:
movf     ADRESH,w       ; Copy the display to the LEDs
    movlw    _1VOLT
    subwf    ADRESH, w
   BNC    LessThan1V                ; Branch if less than 1V


    movlw    _2VOLT
    subwf    ADRESH, w
   BNC    LessThan2V                ; Branch if Between 1V and 2V
   

    movlw    _2_5VOLT
    subwf    ADRESH, w
   BNC    LessThan2_5V             ; Branch if Between 2V and 2.5V


    movlw    _3VOLT
    subwf    ADRESH, w
   BNC    LessThan3V                ; Branch if Between 2.5V and  3V


    movlw    _4VOLT
    subwf    ADRESH, w
   BNC    LessThan4V                ; Branch if Between 3V and 4V


    movlw    _5VOLT
    subwf    ADRESH, w
   BNC    LessThan5V                ; Branch if Between 3V and 4V
    goto      MainLoop
LessThan1V:
   movlw   b'00000001'
   movwf   PORTC
   goto   MainLoop

LessThan2V
   movlw   b'00000010'
   movwf   PORTC
   goto   MainLoop

LessThan2_5V
   movlw   b'00000100'
   movwf   PORTC
   goto   MainLoop

LessThan3V
    movlw   b'00001000'
   movwf   PORTC
   goto   MainLoop

LessThan4V
   movlw   b'00010000'
   movwf   PORTC
   goto   MainLoop

LessThan5V
   movlw   b'00100000'
   movwf   PORTC
   goto   MainLoop

adcdelay:
    nop                 ;1 cycle

    return                 ;4 cycles (including call)
   
     end
 
Last edited:
I guess it probably helps to know what language your using.

I have a classic example of why this is doing my head in,

Using the code that Jon Wilder provided above, I wanted to make the LED flash when I pressed one of the buttons on the programming board (button SW1 triggers RA0).

I added this to the init routine,

movlw 0xFF ;set Port A as all inputs(Obviously removed the line that set them as outputs)
movwf TRISA

I then added this inbetween the init and LED_on routines,

MENU btfss PORTA,0 ;Test if bit 0 of PORTA is a 1 and skip next instruction if it is
goto MENU

But I get nothing, the LED doesn't flash whether im pressing SW1 or not. If I remove the MENU part the LED flashes away. Im trying to start with the basics here but im having no luck, it would have been nice for the Uni to actually teach us some of this stuff first, before expecting us to write a program.

I really appreciate the help by the way.


SCRAP THAT

Just added

MOVLW B'00000111' ;Disable Comparator module's
MOVWF CMCON

To the init routine and all is well.
 
Last edited:
I guess it probably helps to know what language your using.

It's called assembly language. That's why you have to use MPASM to assemble it.

Using the code that Jon Wilder provided above, I wanted to make the LED flash when I pressed one of the buttons on the programming board (button SW1 triggers RA0).

I added this to the init routine,

movlw 0xFF ;set Port A as all inputs(Obviously removed the line that set them as outputs)
movwf TRISA

I then added this inbetween the init and LED_on routines,

MENU btfss PORTA,0 ;Test if bit 0 of PORTA is a 1 and skip next instruction if it is
goto MENU

But I get nothing, the LED doesn't flash whether im pressing SW1 or not. If I remove the MENU part the LED flashes away. Im trying to start with the basics here but im having no luck, it would have been nice for the Uni to actually teach us some of this stuff first, before expecting us to write a program.

I really appreciate the help by the way.

You'll need a pull up resistor on that pin (i.e. a resistor that comes off the + rail and connects to the input pin), then you'll need to wire the other end of the switch to ground. This "sets" your input pin. Without the pull up resistor there, the pin will be in an unknown state.

Your button code would then be -

Code:
		list 		 p=16F627
		include		 <16F627.inc>

		__config	_CP_OFF & DATA_CP_OFF & _LVP_OFF & _BODEN_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT

;No code protection
;No data code protection
;Low Voltage Programming off
;Brown Out Detection Off
;Master Reset pin active
;Power Up Timer on
;Watchdog Timer off
;Internal RC oscillator

LOOP 		EQU		 0x20			;label address 0x20 with LOOP

init		bsf		STATUS, RP0		;change to Bank 1		
		bcf		PCON, OSCF		;set internal oscillator frequency to 37kHz
		movlw		0x00			;set Port A as all outputs
		movwf		TRISA
		movlw		0x00			;set Port B as all outputs
		movwf		TRISB
		bcf		STATUS,RP0		;change to Bank 0

		movlw		0x07			;disable on chip comparator
		movwf		CMCON			

BUTTON		btfsc		PORTA,0			;wait for button to be pressed
		goto		BUTTON

LED_on		bsf		PORTB, 0		;turn on LED

		call		delay_1			;wait

LED_off 	bcf		PORTB, 0		;turn off LED

		call		delay_1			;wait

		btfss		PORTA,0			;if button is pressed a second time, stop flashing
		goto		BUTTON_1		;else continue flashing

		goto		LED_on			;do it again

delay_1	 	movlw		0xFF			;start delay counter at 255
		movwf		LOOP		
W8		decfsz		LOOP, 1			;decriment delay counter, branch if zero
		goto		W8			;go back
		return					;return from subroutine
		
		end

SCRAP THAT

Just added

MOVLW B'00000111' ;Disable Comparator module's
MOVWF CMCON

To the init routine and all is well.

Ah yes...the comparator module will get you everytime. Surprised I didn't catch that as I'm very familiar with the 16F628 (same as the F627 but with 2K program ROM instead of 1K). You can also use the hex equivalent -

Code:
                movlw		0x07			;disable on chip comparator
		movwf		CMCON

0x denotes hex radix.
 
Last edited:
Here you something to look over
Code:
MainLoop: 
   movf     sig_value,w       ; Copy the display to the LEDs
    movlw    Signal_1
    subwf    sig_value, w
   BNC    LessThan1               ; Branch if less than 1V


    movlw    Signal_2
    subwf    sig_value, w
   BNC    LessThan2                ; Branch if Between 1V and 2V
   

    movlw    Signal_3
    subwf    sig_value, w
   BNC    LessThan2_3            ; Branch if Between 2V and 2.5V


    movlw    Signal_4
    subwf    sig_value, w
   BNC    LessThan4               ; Branch if Between 2.5V and  3V


    goto      MainLoop
LessThan1:
   movlw   b'00000001'
   movwf   PORTC               ;displays to portc put what you want too happen
   goto   MainLoop

LessThan2
   movlw   b'00000010'
   movwf   PORTC
   goto   MainLoop

LessThan3
   movlw   b'00000100'
   movwf   PORTC
   goto   MainLoop

LessThan4
    movlw   b'00001000'
   movwf   PORTC
   goto   MainLoop



    return                 ;4 cycles (including call)
   
     end
 
Yes that's exactly what im doing. I have looked at MPLAB IDE and code composer and about a million other programs, but to be honest, I want to keep it simple at first, using big complicated programs with loads of options just makes it more likely that there's going to be some kind of mistake, by me of course.

I have gotten used to the simplicity of compiling with just a programming editor, and punching a macro button, as opposed to a full blown IDE. Probably comes down to what you learn on. Using something like Eclipse as a coding environment is a major adjustment, and an ongoing process for me.
 
I've been using a text editor called Vim. It's an open source text editor that changes the text color according to the syntax of your code if you save the file with a file extension that matches up with a coding language. This makes it easy to spot syntax errors in your code. Then I use MPASM to assemble it. It's available for Unix based OS'es (i.e. Linux) as well as Windows.

You can download it here -

https://www.vim.org/download.php
 
Last edited:
Cheers guys, at the moment im using the experiment/programmer board, so all the switches and LEDs seem to be set up correctly, but i'll have to keep that in mind when im actually building the thing myself. I think im getting it though, just managed to write a program that counts how long I hold the button down and displays the result in binary using the LEDs, if I press the button really fast 'track and field' style you can see the LEDs building up 1, 10, 11, 100 etc etc. Sweet, I now have some hope that I may be able to do this project. Any ideas on how I can compare two numbers as I mentioned before would be very much appreciated, but other than that you've helped me no end, seriously stressing out a couple of days ago.

Sorry be80be, didn't see your post, i'll check that out later, got some NYE drinking to be done now. Happy New Year!!!
 
Last edited:
RoveyDoveyGrovey:

Not an assembler programmer, but If I'm not mistaken be80be's BNC is an 18f instruction. No help for the 16f627 (unless it's a 16f asm mnemonic?). This means involving subwf, btfsc of the Status.C bit, and goto, which is why I like a hll language.

I've been using a text editor called Vim. It's an open source text editor that changes the text color according to the syntax of your code if you save the file with a file extension that matches up with a coding language. This makes it easy to spot syntax errors in your code. Then I use MPASM to assemble it. It's available for Unix based OS'es (i.e. Linux) as well as Windows.

You can download it here -

download : vim online
I know this is OTP (can't help myself), but I find it hard to imagine going back 30 yrs. to my first editor introduction with IBM Edlin....ughhhh. I have a brother that loves VIM :rolleyes:
 
Cheers guys, at the moment im using the experiment/programmer board, so all the switches and LEDs seem to be set up correctly, but i'll have to keep that in mind when im actually building the thing myself. I think im getting it though, just managed to write a program that counts how long I hold the button down and displays the result in binary using the LEDs, if I press the button really fast 'track and field' style you can see the LEDs building up 1, 10, 11, 100 etc etc. Sweet, I now have some hope that I may be able to do this project. Any ideas on how I can compare two numbers as I mentioned before would be very much appreciated, but other than that you've helped me no end, seriously stressing out a couple of days ago.

Sorry be80be, didn't see your post, i'll check that out later, got some NYE drinking to be done now. Happy New Year!!!

If you want to see if the numbers are the same value, you either subtract or "xor" the numbers (i.e. Exclusive OR) to be compared then poll the Z flag (i.e. the "Zero" flag) in the STATUS register. The Z flag gets set anytime the result of a math operation equals zero. Since only numbers of identical values can return a zero result on a subtract or a xor operation, the Z flag tells you if they're the same or not.

Say for example you have a constant stored in a general purpose RAM register file labeled "NUMBER" and you want to see if it is equal to 0x0F (0x0F is just an arbitrary number for the sake of conversation) -

Code:
		movlw		0x0F			;see if value of register file NUMBER
		subwf		NUMBER,W		;is equal to 0x0F. Store result in W register.
		btfsc		STATUS,Z		;branch if equal (if result of subraction operation = 0)
		goto		A

Mathematical operations are known as "two operand instructructions". In two operand instructions, you have the file address or file address label, and a designator. The designator tells the assembler where to store the result of the operation.

You have two choices as to where to store the result of the operation...the W register or into the source register file itself. A ",W" after the file address or label makes it store the result of the operation in the W register (i.e. the "working register") so that the original value that resides in register file (in this case register file NUMBER) does not get altered. A ",F" after the file address or file address label would make it store the result of the operation into the register file itself.

You can also use "xorwf" in place of "subwf".

Code:
		movlw		0x0F			;see if value of register file NUMBER
		xorwf		NUMBER,W		;is equal to 0x0F. Store result in W register.
		btfsc		STATUS,Z		;branch if equal (if result of subraction operation = 0)
		goto		A

XOR is "Exclusive OR" and is a logic operation. Essentially with XOR, both values have to be non-identical to be "TRUE" (i.e. "High", 1, or non-zero result...either 1 value OR the other). If they are identical, they will always be "FALSE" when XOR'ed together (i.e. "Low", or 0), which will set the Z flag. In IOR (Inclusive OR or simply OR), both values can be either identical or non-identical and be "TRUE".

You can also use the special instruction nemonic "bz", which means "Branch on Zero" -

Code:
		movlw		0x0F			;see if value of register file NUMBER
		subwf		NUMBER,W		;is equal to 0x0F. Store result in W register.
		bz		A			;branch if equal (if result of subraction operation = 0)

The "bz A" will generate the code -

Code:
 		btfsc		STATUS,Z		;branch if equal (if result of subraction operation = 0)
		goto		A

...when you assemble the file.

nickelflippr said:
Not an assembler programmer, but If I'm not mistaken be80be's BNC is an 18f instruction. No help for the 16f627 (unless it's a 16f asm mnemonic?).

And yes, BC, BNC, BZ, and BNZ are all special instruction mnemonics for "Branch on Carry", "Branch on No Carry", "Branch on Zero" and "Branch on No Zero" and they also apply to the mid-range family of PICs. Check page 7 of this PDF from Microchip which shows applicable special instruction mnemonics for the 12/14 bit core -

https://www.electro-tech-online.com/custompdfs/2010/12/mpasm-card.pdf
 
Last edited:
I can code for any PIC I didn't post something that wouldn't work with your chip
I just used some of the mnemonics instruction that you can use. The 18F have more instructions.

But the 16f can use these look at attachment

Jon Wilder Thanks for the link I haven't seen that pdf before nice pdf.
 

Attachments

  • LIKE_thisOne.PNG
    LIKE_thisOne.PNG
    70.1 KB · Views: 178
Last edited:
nickelflippr notepad++ is real good editor But the OP really needs to get MPLAB and just use MPASM that comes with it. would be a lot easier to learn asm. with it you have the MPASM help files to guide you and your still compiling with the same compiler

I don't use asm that much but you need it with a hill @asm LOL for timing mostly.
 
Last edited:
Jon Wilder Thanks for the link I haven't seen that pdf before nice pdf.

Not a problem. I stumbled upon it while searching for some other stuff related to MPASM. Printed it out for quick reference. Makes my coding a bit easier.

The thing I like about PICs is that the instruction set seems to apply to the entire core rather than just one PIC. This means if you learn the instruction set for one PIC in a given core family you pretty much know the instruction set for the entire core and just have to learn the chip specific peripherals, memory map and configuration bit map.
 
Last edited:
Jon Wilder, be80be:

Thanks for confirming the BNC etc. mnemonics for the 10/12 bit families, and also for the pdf. Should have known, I actually use #define, and ifdef a lot. My apologies for being lazy this morning.

I use Crimson Editor with Basic, and have previously downloaded and looked at notepad++, can't remember why I didn't go with it. I will occasionally use MPLAB, mostly for interrogating .asm files with the simulator, and stopwatch.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top