Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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.
I want to store about 10 Bytes of data in each array.
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
;******************************************************************************
; *
; 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
/*
;******************************************************************************
; *
; 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;
}
/*
;******************************************************************************
; *
; 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);
}
}
This is my ASM and C code. The C code is better tho as you can alter it easier (less work).
;
; 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 ;
;
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