rallysteve
Newbie level 6
I have created this piece of code from two smaller pieces of code I have been working on, one to do Analogue to Digital Conversions and the other to deal with interrupts and send data through the serial port. I have combined the two programs 99% sucessfully except for problems enabling the external interrupts.
The System reads the 8 A/D channels on the Atmel 89C51CC03 (I know the include file is for CC01 but if i change it to CC03 I get loads of errors :shock: ) the system then outputs the 8 bit value of each channel through the Serial Port with a start and stop bit.
When assembling in Keil uVision 4 I get the following error "test.a51(44): error A17: INVALID BYTE BASE IN BIT ADDRESS EXPRESSION" However this instruction worked fine before I added the A/D conversion code to it and im not sure what the problem is now??
I have commented the four lines below out and the program compiles and runs nicely in simulator except for the fact the interrupts wont trigger (presumably as they have not been Enabled!):
My full code is seen below, any help much appreciated cheers Steve
The System reads the 8 A/D channels on the Atmel 89C51CC03 (I know the include file is for CC01 but if i change it to CC03 I get loads of errors :shock: ) the system then outputs the 8 bit value of each channel through the Serial Port with a start and stop bit.
When assembling in Keil uVision 4 I get the following error "test.a51(44): error A17: INVALID BYTE BASE IN BIT ADDRESS EXPRESSION" However this instruction worked fine before I added the A/D conversion code to it and im not sure what the problem is now??
I have commented the four lines below out and the program compiles and runs nicely in simulator except for the fact the interrupts wont trigger (presumably as they have not been Enabled!):
Code:
SETB IE.0 ; Enable External Interrupt 0
SETB IE.2 ; Enable External Interrupt 1
SETB IE.7 ; Global Interrupt Enable
SETB IP.0 ; Set Priority of Interrupt 0 higher than 1
My full code is seen below, any help much appreciated cheers Steve
Code:
/* Transmitter Program - Steven Newton A813349 - Stage Lighting Controller - Part D Project */
$NOMOD51 ; Ask Keil not to define 8051 registers
$INCLUDE (t89c51cc01.INC) ; Include file
value_converted DATA 10H; ; Conversion Value
AD_0 DATA 11H ; Channel 0 Data
AD_1 DATA 12H ; Channel 1 Data
AD_2 DATA 13H ; Channel 2 Data
AD_3 DATA 14H ; Channel 3 Data
AD_4 DATA 15H ; Channel 4 Data
AD_5 DATA 16H ; Channel 5 Data
AD_6 DATA 17H ; Channel 6 Data
AD_7 DATA 18H ; Channel 7 Data
end_of_convertion BIT 20H; ; End of Conversion Flag
ORG 00000H
START:
JMP SETUP
ORG 00003H
JMP INT_1 ; Interrupt 1 (MB) P3.2
ORG 00013H
JMP INT_2 ; Interrupt 2 (Hold) P3.3
ORG 00043h
LJMP adc_it ; Save Conversion Value
ORG 00050H
LJMP SETUP
ORG 00100H
SJMP BEGIN
SETUP:
/* Setup Hardware Interrupts */
SETB IE.0 ; Enable External Interrupt 0
SETB IE.2 ; Enable External Interrupt 1
SETB IE.7 ; Global Interrupt Enable
SETB IP.0 ; Set Priority of Interrupt 0 higher than 1
BEGIN:
/* Set Up ADC and UART */
MOV ADCF,#0C0h ;
MOV ADCLK,#06h ; Fosc = 16 MHz, Fadsc = 153.8khz
MOV ADCON,#20h ; Enable the ADC
SETB EA ; enable interrupts
SETB EADC ; enable ADC interrupt
MOV SCON,#050H ; Mode 1, 8 Bit UART, Variable baud rate
MOV TMOD,#020H ; TImer 1, Mode 2, 8-Bit Auto Reload
MOV TH1,#0F4H ; Reload Value for 2400Baud @ 11.0592MHz
SETB TR1 ; Set Timer to run
SETB TI ; Set Ti ready to send 1st charactor
SETB TCON.1 ; Level Sensitive Input
LOOP:
/* Channel 0 */
ANL ADCON,#~07h ; Clear the channel field ADCON[2:0]
ORL ADCON, #00h ; Select channel 0
ANL ADCON,#~40h ; standard mode
ORL ADCON, #08h ; Start conversion
JNB end_of_convertion,$ ; Wait end of convertion
CLR end_of_convertion ; Clear software flag
MOV AD_0,value_converted ; Save converted value
/* Channel 1 */
ANL ADCON,#~07h ; Clear the channel field ADCON[2:0]
ORL ADCON, #01h ; Select channel 1
ANL ADCON,#~40h ; standard mode
ORL ADCON, #08h ; Start conversion
JNB end_of_convertion,$ ; Wait end of convertion
CLR end_of_convertion ; Clear software flag
MOV AD_1,value_converted ; Save converted value
/* Channel 2 */
ANL ADCON,#~07h ; Clear the channel field ADCON[2:0]
ORL ADCON, #02h ; Select channel 2
ANL ADCON,#~40h ; standard mode
ORL ADCON, #08h ; Start conversion
JNB end_of_convertion,$ ; Wait end of convertion
CLR end_of_convertion ; Clear software flag
MOV AD_2,value_converted ; Save converted value
/* Channel 3 */
ANL ADCON,#~07h ; Clear the channel field ADCON[2:0]
ORL ADCON, #03h ; Select channel 3
ANL ADCON,#~40h ; standard mode
ORL ADCON, #08h ; Start conversion
JNB end_of_convertion,$ ; Wait end of convertion
CLR end_of_convertion ; Clear software flag
MOV AD_3,value_converted ; Save converted value
/* Channel 4 */
ANL ADCON,#~07h ; Clear the channel field ADCON[2:0]
ORL ADCON, #04h ; Select channel 4
ANL ADCON,#~40h ; standard mode
ORL ADCON, #08h ; Start conversion
JNB end_of_convertion,$ ; Wait end of convertion
CLR end_of_convertion ; Clear software flag
MOV AD_4,value_converted ; Save converted value
/* Channel 5 */
ANL ADCON,#~07h ; Clear the channel field ADCON[2:0]
ORL ADCON, #05h ; Select channel 5
ANL ADCON,#~40h ; standard mode
ORL ADCON, #08h ; Start conversion
JNB end_of_convertion,$ ; Wait end of convertion
CLR end_of_convertion ; Clear software flag
MOV AD_5,value_converted ; Save converted value
/* Channel 6 */
ANL ADCON,#~07h ; Clear the channel field ADCON[2:0] */
ORL ADCON, #06h ; Select channel 6 */
ANL ADCON,#~40h ; standard mode */
ORL ADCON, #08h ; Start conversion */
JNB end_of_convertion,$ ; Wait end of convertion */
CLR end_of_convertion ; Clear software flag */
MOV AD_6,value_converted ; Save converted value */
/* Channel 7 */
ANL ADCON,#~07h ; Clear the channel field ADCON[2:0] */
ORL ADCON, #07h ; Select channel 7 */
ANL ADCON,#~40h ; standard mode */
ORL ADCON, #08h ; Start conversion */
JNB end_of_convertion,$ ; Wait end of convertion */
CLR end_of_convertion ; Clear software flag */
MOV AD_7,value_converted ; Save converted value */
SEND_DATA:
/* Send Converted Data for 8 Channels to Serial Buffer with Start and Stop Bits */
MOV R1,#02BH ; Preload R1 with start bit (+)
MOV SBUF,R1 ; Load Start Bit into Serial Buffer
CLR TI ; Clear Charactor sent flag
CALL WAIT ; Wait for charactor to be set
MOV SBUF,AD_0 ; Load Channel 0 into Serial Buffer
CLR TI
CALL WAIT
MOV SBUF,AD_1 ; Load Channel 1 into Serial Buffer
CLR TI
CALL WAIT
MOV SBUF,AD_2 ; Load Channel 2 into Serial Buffer
CLR TI
CALL WAIT
MOV SBUF,AD_3 ; Load Channel 3 into Serial Buffer
CLR TI
CALL WAIT
MOV SBUF,AD_4 ; Load Channel 4 into Serial Buffer
CLR TI
CALL WAIT
MOV SBUF,AD_5 ; Load Channel 5 into Serial Buffer
CLR TI
CALL WAIT
MOV SBUF,AD_6 ; Load Channel 6 into Serial Buffer
CLR TI
CALL WAIT
MOV SBUF,AD_7 ; Load Channel 7 into Serial Buffer
CLR TI
CALL WAIT
MOV R1,#020H ; Preload R1 with end bit (SPACE)
MOV SBUF,R1 ; Load R1 into the Serial Buffer
CLR TI
CALL WAIT ; Clear Charactor sent flag
JMP LOOP
WAIT: JNB TI,WAIT ; Wait for Charactor to be sent
RET ; Return to
INT_1:
/* Interrupt to Trigger Master Black Out */
PUSH PSW ; Push Program Status Word to the Stack
CLR P2.0 ; Turn on the Master Blackout LED
MOV A,#042H ; Load the letter B into Accumulator
MOV SBUF,A ; Load data into Serial Buffer
CLR TI ; Clear the Charactor Sent Flag
WAIT1: JNB TI,WAIT1 ; Wait for Charactor to be sent
SETB P2.0 ; Turn off the Master Blackout LED
POP PSW ; Pop Processor Data from the Stack
RETI ; Return from interrupt routine
INT_2:
/* Interrupt to Trigger Master Black Out */
PUSH PSW ; Push Program Status Word to the Stack
CLR P2.1 ; Turn on the Hold LED
MOV A,#048H ; Load the letter H into Accumulator
MOV SBUF,A ; Load data into Serial Buffer
CLR TI ; Clear the Charactor Sent Flag
WAIT2: JNB TI,WAIT2 ; Wait for Charactor to be sent
SETB P2.1 ; Turn off the Hold LED
POP PSW ; Pop Processor Data from the Stack
RETI ; Return from interrupt routine
ADC_IT:
ANL ADCON,#~10h ; Clear the End of conversion flag
MOV value_converted,ADDH ; Save value
SETB end_of_convertion; ; Set flag
RETI ; Return from Interrupt
END