I'm using the MCB900 with a P89LPC938 and the LPC900 development tools (demo version). I'm trying to test the A/D. Couple of things:
1. REG938.H doesn't list the A/D interrupt enable bit EADC (IEN2.1). So I added it to REG938.H:
sbit EADC = IEN2^1; // ADC int
But afterwards, I get a compiler error:
REG938.H(184): error C146: 'IEN2': invalid base address
Any ideas?
For now, I bypassed it by doing this in code:
// EADC = 0x01; IEN2 |= 0x02; // Enable A/D interrupt
2. After much futzing around in the following code, if I set EA, it doesn't work; commented out, it works fine.
#include "REG938.H" bit btADComp; void main(void) { P2M1 = 0x00; // set P2 to quasi-bi P2M2 = 0x00; P0M1 = 0xFF; // set P0 as input only (for A/D) P0M2 = 0x00; // set P0 as input only ADCON0 &= 0xDC; // disable all triggers ADMODA &= 0x0F; // clear mode bits and boundary interrupt flag ADINS |= 0x04; // select AD02 for sampling & conversion (P0.3) ADCON0 |= 0x44; // enable ADC ADMODA = 0x10; // single conversion mode ADMODB = 0x00; // no 4 conv. int. mode, no boundary, clk divider = 1 IEN2 |= 0x02; // Enable A/D interrupt // EA = 1; // Enable all interrupts btADComp = 0; // clear while(1) // main loop { ADCON0 |= 0x01; // Immediate start while (btADComp == 0); // wait until done P2 = AD0DAT2R; // copy LSB result to Port 2 (LEDs) btADComp = 0; // clear it } } void adc_isr (void) interrupt 14 using 1 { if (ADCON0 & 0x08) { ADCON0 &= ~0x08; // clear ADCI0 flag btADComp = 1; // set our flag } }
Even Code Architect states to enable EA after init, although it's not in its code. Why would setting EA cause it to stop working?
this is an SFR whose bits can be declared as an "sbit".
Argh, all that previewing, and still a typo. The above of course has to read:
this is an SFR whose bits can not be declared as an "sbit".
Thanks for the SFR/sbit note. I guess the SFR address has to be byte-aligned to declare sbit's. New one on me.
It's unlikely anybody will be able to help you if you don't expand on that "it doesn't work" thingy.
I know it's vague, but the code is pretty simple. If I don't set EA, the LEDs go blinky.
When editing the .H file, did you by chance delete or botch the original EA sbit assingment?
Nope, untouched in REG938.H:
sbit EA = IEN0^7;