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

Arrays In ASM

Status
Not open for further replies.

AtomSoft

Well-Known Member
How do i create a array in asm? I want to store about 10 Bytes of data in each array.

Do i use Tables, EEPROM, or some other solution? And any sample would rock also.
 

ericgibbs

Well-Known Member
Most Helpful Member
How do i create a array in asm? I want to store about 10 Bytes of data in each array.

Do i use Tables, EEPROM, or some other solution? And any sample would rock also.
hi atom,
Do you mean an array or a list.?

An Array would be eg: 10*10 elements.
 

AtomSoft

Well-Known Member
i need a array of bytes. like

Array[10] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A};

In C its something like that. But i need to be able to edit the array.
I want to store about 10 Bytes of data in each array.
Not to vague lol

1 Array to hold 10 bytes of data.

10 * 1 Byte meaning about 10 Variables but instead of calling each i want to be able to use a pointer or something to access each from a main var. I tried something like:

Code:
	movlw 	Tag01 
	addwf	pntr,0
	movwf	FSR0L
	; I need this part now.. How do i save my data to new spot in FSR?
	incf 	pntr
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
The FSR registers are pointers and you access what they are pointing to through the INDF register. If you're on a 16 series chip there is also the IRP bit in the status register to set as well.

Edit, with your above code you would just store something in INDF and it would go in location pointer+Tag01.

Mike.
 
Last edited:

Nigel Goodwin

Super Moderator
Most Helpful Member
In PIC assembler there's one pointer, which you can use to access the GPR's, that appears to be what you're looking for.

Check out "Indirect Addressing, INDF and FSR Registers" in the datasheet.
 

AtomSoft

Well-Known Member
Awesome!
Code:
	movlw 	Tag01 ;set starting address
	addwf	pntr,0
	movwf	FSR0L
	movf	tmp1, w
	movwf	INDF0
	incf 	pntr
works well!
 
Last edited:

AtomSoft

Well-Known Member
Thanks again this is for all those people who use that Radio Shack RFID reader (SERIAL). This code accurately gets the 12 bytes and stores it in a variable. This is my ASM and C code. The C code is better tho as you can alter it easier (less work).

Radio Shack: http://www.radioshack.com/product/index.jsp?productId=2906723
Parallax: http://www.parallax.com/StoreSearch...List/0/SortField/4/ProductID/114/Default.aspx


ASM CODE:
Code:
;******************************************************************************
;                                                                             *
;    Filename: RFID READER                                                    *
;    Date: Sunday, May 05, 2009                  	                          *
;    File Version: 001                                                        *
;                                                                             *
;    Author:   Jason Lopez                                                    *
;    Company:  AtomSoft                                                       *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Files Required: P18F2525.INC                                             *
;                                                                             *
;******************************************************************************

	LIST P=18F2525	;directive to define processor
	#include <P18F2525.INC>	;processor specific variable definitions


    CONFIG	OSC = INTIO67, WDT = OFF, LVP = OFF, XINST = OFF
	

#DEFINE rxP PORTC
#DEFINE rx 7

		CBLOCK	0x000
		d1
		d2
		d3
		tmp1
		pntr
		Tag01
		Tag02
		Tag03
		Tag04
		Tag05
		Tag06
		Tag07
		Tag08
		Tag09
		Tag10
		Tag11
		Tag12
		ENDC

		ORG	0x0000
	bra Init

		ORG	0x0008
	bra	HighInt

Init:
	movlw	0x72
	movwf	OSCCON
	movlw	0x0F
	movwf	ADCON1
	movlw	0xC0
	movwf	INTCON
	movlw	d'0'
	movwf	pntr
UsartInit: ; at 8Mhz it will be 2400 bps.
	clrf	RCSTA
	clrf	TXSTA
	bcf		TXSTA, BRGH
	bcf		TXSTA, SYNC
	bcf		BAUDCON, BRG16
	movlw	0x00
	movwf	SPBRGH
	movlw	d'51'
	movwf	SPBRG
	movlw	0x90
	movwf	RCSTA
	bsf		TRISC,7
	bsf		TRISC,6
	bsf		PIE1, RCIE
	bsf		IPR1, RCIP	;Make Recieve High Priority
	bcf		PIR1, RCIF
	
Main:
	movlw	0x0C
	cpfslt	pntr
	clrf	pntr
	goto 	Main

HighInt:
	movff	RCREG, tmp1
	movlw 	Tag01 ;set starting address of my table
	addwf	pntr,0
	movwf	FSR0L
	movf	tmp1, w
	movwf	INDF0
	incf 	pntr

	bcf		PIR1, RCIF
	clrf	PORTC
	retfie	FAST
	END
C Code. No overrun issues anymore!
Code:
/*
;******************************************************************************
;                                                                             *
;    Filename: RFID READER                                                    *
;    Date: Sunday, May 05, 2009                  	                          *
;    File Version: 001                                                        *
;                                                                             *
;    Author:   Jason Lopez                                                    *
;    Company:  AtomSoft                                                       *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Files Required: P18F2525.INC                                             *
;                                                                             *
;******************************************************************************
*/
#include <p18f2525.h>
#include <delays.h>


#pragma config WDT = OFF, LVP = OFF, OSC = INTIO67, XINST = OFF

/************************************
Prototypes
*************************************/
void main(void);
void delay_ms(unsigned int mS);
void delay_s(int S);
void rx_isr (void);

/************************************
Variables and Defines
*************************************/
	unsigned char tempID[12];
	unsigned char pntr;

#pragma code InterruptVectorHigh = 0x08
void
InterruptVectorHigh (void)
{
  _asm
    goto rx_isr //jump to interrupt routine
  _endasm
}
#pragma code
/************************************
Main
*************************************/
void main(void){
	char x;

	OSCCON = 0x72;      			//8MHz clock
	while(!OSCCONbits.IOFS);		//wait for osc stable

	INTCON = 0xC0;
	RCSTA = TXSTA = 0x00;
	BAUDCONbits.BRG16 = 0;
	SPBRGH = 0x00;
	SPBRG = 51;
	RCSTA =	0x90;
	TRISCbits.TRISC7 = 1;		//Set both PORTC 7 and 6 as inputs.
	TRISCbits.TRISC6 = 1;
	IPR1bits.RCIP = 1;			//Make Rx High Priority
	PIE1bits.RCIE = 1;			//Enable Rx Interrupt
	PIR1bits.RCIF = 0;  		//Ensure Clear Flag
	pntr = 0x00;

	while(1){
		if(pntr == 12) pntr = 0;
	}
}
/************************************
Rx Intterup (HIGH)
*************************************/
#pragma interrupt rx_isr
void rx_isr (void){

	tempID[pntr] = RCREG;
	pntr++;
	PIR1bits.RCIF = 0;
	PORTC = 0;
}
 
Last edited:

AtomSoft

Well-Known Member
Now with Bi color LED and test to see if its me:
Code:
/*
;******************************************************************************
;                                                                             *
;    Filename: RFID READER                                                    *
;    Date: Sunday, May 05, 2009                  	                          *
;    File Version: 002                                                        *
;                                                                             *
;    Author:   Jason Lopez                                                    *
;    Company:  AtomSoft                                                       *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Files Required: P18F2525.INC                                             *
;                                                                             *
;******************************************************************************
*/
#include <p18f2525.h>
#include <delays.h>
#include <string.h>

#pragma config WDT = OFF, LVP = OFF, OSC = INTIO67, XINST = OFF

/************************************
Prototypes
*************************************/
void main(void);
void delay_s(int s);
void rx_isr (void);
void ErrLed(void);
void OkLed(void);
/************************************
Variables and Defines
*************************************/
	unsigned char tempID[12];
	unsigned char pntr;

	#define LEDC LATCbits.LATC0
	#define LEDA LATCbits.LATC1


/************************************
Interrupt Vectors
*************************************/
#pragma code InterruptVectorHigh = 0x08
void
InterruptVectorHigh (void)
{
  _asm
    goto rx_isr //jump to interrupt routine
  _endasm
}
#pragma code
/************************************
Main
*************************************/
void main(void){
	char x;
	unsigned char AtomID[12] = {10,48,70,48,51,48,52,48,51,69,65,13};

	OSCCON = 0x72;      			//8MHz clock
	while(!OSCCONbits.IOFS);		//wait for osc stable

	TRISC = RCSTA = TXSTA = 0x00;

	INTCON = 0xC0;
	BAUDCONbits.BRG16 = 0;
	SPBRGH = 0x00;
	SPBRG = 51;
	RCSTA =	0x90;
	
	TRISCbits.TRISC7 = 1;		//Set both PORTC 7 and 6 as inputs.
	TRISCbits.TRISC6 = 1;

	IPR1bits.RCIP = 1;			//Make Rx High Priority
	PIE1bits.RCIE = 1;			//Enable Rx Interrupt
	PIR1bits.RCIF = 0;  		//Ensure Clear Flag
	pntr = 0x00;

	while(1){
		if(pntr >= 12) {
			pntr = 0;

			if(memcmp(AtomID,tempID,12) == 0){
				OkLed();
				delay_s(2);
			}

		}
		ErrLed();
	}
}
/************************************
Rx Intterup (HIGH)
*************************************/
#pragma interrupt rx_isr
void rx_isr (void){

	tempID[pntr] = RCREG;
	pntr++;
	PIR1bits.RCIF = 0;
	PORTC = 0;
}

void ErrLed(void){
	LEDA = 1;
	LEDC = 0;
}
void OkLed(void){
	LEDA = 0;
	LEDC = 1;
}
void delay_s(int s){
	int x;

	for(x=0;x<s;x++){
		Delay10KTCYx(200);
	}
}
 
Last edited:

Mike - K8LH

Well-Known Member
This is my ASM and C code. The C code is better tho as you can alter it easier (less work).
Hi Jason,

Yes, assembler is more work but you could always create a macro or two to emulate those high level language functions.

Code:
;
;  new interrupt code example
;
HighInt
        Array   Tag01,pntr      ; setup FSR0 = &Tag01[pntr]
        movff   RCREG,INDF0     ;
        incf    pntr,F          ;
;       bcf     PIR1,RCIF       ; not required, reading RCREG clears flag
        retfie  FAST            ;
Code:
;
Array   macro   vArray,vIndex
        lfsr    0,vArray        ; FSR0 = &vArray[0]
        movf    vIndex,W        ; index, 0..255
        addwf   FSR0L,F         ; FSR0 = &vArray[vIndex]
        btfsc   STATUS,C        ; carry? no, skip, else
        incf    FSR0H,F         ; bump FSR0H
        endm
 

AtomSoft

Well-Known Member
cool thanks. I added a relay circuit and now can control a nice high voltage. using a Optocoupler instead of transistor and a nice relay:

2A @ 30VDC
1A @ 125vAC
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top