Hier ist die data_write-Funktion, die ich mir anschaue. Mir wurde gesagt, dass diese Methode (aus dem Lehrbuch) nicht gut ist und ich die C-Methode verwenden sollte (die derzeit auskommentiert ist). Wenn die Cbits-Methode verwendet wird, erkennt der Compiler alle Argumente nach _asm/_endasm nicht die Bitnamen (sie werden nicht grün).
Wenn ich nur die Assembly-Methode verwende, erhalte ich eine Reihe von Fehlern [1111] über das undefinierte Label (WR, GIE, EECON1 usw.) innerhalb dieser Funktion. Muss ich die ADC.h innerhalb der Funktion irgendwie neu definieren? Grundsätzlich werden alle Registernamen (EECON1 usw.) und Bitnamen (WR, WREN usw.) nicht innerhalb der Funktion "data_write" erkannt, wenn sie sich innerhalb der Assembly-Tags (_asm/_endasm) befinden. Wenn ich die Cbits.BIT-Methode verwende, erhalte ich einen generischen Syntaxfehler und die Bits nach _endasm werden nicht identifiziert (werden grün).
#include <stdio.h>
#include <stdlib.h>
#include <p18f452.h>
#include <delays.h>
#include <adc.h>
int result; // used in ADC result handling
int write_point=0x64; // used in data_write function. initial=d100
void data_write (int write_point, int result); // declare prototype
void main(void) // <==should this be 'int main (void)' b/c i'm passing result to another function ?
{
while (1) {
// sensor 1 configured to port AN0
OpenADC(ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_5ANA_0REF, ADC_CH0 & ADC_INT_OFF);
//configures ADC for port AN0 = sensor 1 input
ConvertADC(); // initiate conversion of sensor1 @ AN0
while(BusyADC()); // waiting to complete conversion
result=ReadADC(); // read the result of sensor1 @ AN0
data_write(result, write_point);
CloseADC();
}
}
void data_write (int write_point, int result) {
/* EECON1bits.EEPGD = 0 // points to data memory
EECON1bits.CFGS = 0 // access data eeprom
EECON1bits.WREN = 1 // enable write to data eeprom
INTCONbits.GIE=0 // disable interrupt
** if I substitute this method of bit control, this 2nd portion belongs after
* the asm arguments, but the bits (WR, GIE, WREN) will not be identified
* either an I get a syntax error. (of course commenting out the bcf/bsf statements)
EECON1bits.WR = 1 // enable bit to start the write operation
INTCONbits.GIE = 1 // re-enable interrupt
EECON1bits.WREN = 0 // restores the write command to =disabled */
_asm
movlw write_point // starting data memory address = data_adr
movwf EEADR,A
movlw result // gets data stored in "result" variable
movwf EEDATA,A // places data into data memory holder
bcf EECON1,EEPGD,A // points to data memory
bcf EECON1,CFGS,A // access data eeprom
bsf EECON1,WREN,A // enable write to data EEPROM
bcf INTCON,GIE,A // disable interrupt
movlw 0x55 // start flash erase sequence
movwf EECON2,A
movlw 0xAA
movwf EECON2,A // end flash erase sequence
bsf EECONN1,WR,A // enable bit to start the write operation
bsf INTCON,GIE,A // re-enable interrupt
bcf EECON1,WREN // restores the write command to =disabled
_endasm
write_point = write_point+2; // increment address by 2
if (write_point >= 0xC6) // if address >= d'198
write_point = 0x64; // resets starting point to d'100
}
Für den auskommentierten C-Teil scheinen Sie keine abschließenden Semikolons zu haben (z. B. sollte die erste Zeile EECON1bits.EEPGD = 0;
) sein, also wird das dem Compiler sicherlich nicht gefallen.
Für die Inline-Assembly, IIRC, sollten die Registernamen verwendbar sein, aber ich denke, Sie müssen die Operanden vollständig angeben (z. B. anstelle von you do). Es ist movwf EECON2,A
möglich, movwf EECON2,0
dass
die Bitnamen auch durch Zahlen anstelle von Namen angegeben werden, z. B. anstelle von bcf EECON1,EEPGD,A
Ihnen bcf EECON1, 7, 0
(EEPGD ist Bit 7 von EECON1) Das A
am Ende ist sowieso nicht richtig, das sollte 1 oder 0 sein (oder W oder F in MPASM)
Es ist eine Weile her, seit ich die Inline-Assembly für so etwas verwendet habe, also ist der Speicher unscharf, aber probiere es aus und lass uns wissen, wie es läuft.
Markieren