??? 01/10/08 12:08 Read: times |
#149215 - Problem solved...almost... Responding to: ???'s previous message |
Hi Mr.Karas,
Thanks for your reply. You are right in stating that "can see lots and lots of usage of the A register in this mainline code" and I also agree with the fact that the accumulator value at any instance is going to be trashed by my ISR. BUT I am using the PUSH ACC and POP ACC to take a 'backup' of the value and place it in the Stack pointer for that very specific reason, but thanks for pointing me that out. Something that you said that had brought my attention and that it actually solved my main problem is the first part of your reply where you state that "the interrupt programming is likely to break almost all the time". I agree 100% and hence I have modified the program to enable the external and global interrupt just before waiting for a flag to occur. I also admit that I am somewhat not using interrupts as they should. I mean, the main advantage of an interrupt is that you can save cycles from checking a software flag in the first place. But here i have used the ISR for the sole reason to be 100% sure that the ADC0804 (analog to digital converter) digital value is ready to be read. In the ADC0804 datasheet the manufacturer states that the digital value must not be read immediatley after the conversion is ready, hence to avoid reading an erroneous digital value from the adc i used the ISR. Yes, I am considering to redisign the whole program to be more elegant and inline with more traditional use of interrupts. Regarding the reply about comments, yes I apologise for writing the whole program--including comments=--in capital letters. I will sort that out when I'll write a new code as stated before. Anyway, the program now works almost fine. I have analyzed the received samples via a software which is similar to Realterm (freeware). It displays received data in HEX and confirmed the data received is as follows: N0$N1ÿN2ÿN3ÿN4ÿN5ÿN6ÿN7ÿN8ÿN9N0$N1ÿN2ÿ....etc etc Honestly I am still thinking of a way to avoid these unwanted 'ÿ' (as in N9N0--note there is no ÿ). Since I am using only one ADC the data received makes sense but I must avoid sending continously a ÿ. Perhaps I have to include pulldown resistors for the bits going from the ADC to port0 of the 8051....I'll try and report....But If the problem is related to the code written please, do point it out. Below is the updated code: ;PROGRAM MODIFIED TO USE EXTERNAL INTERRUPT INT0 ;NOTE: MAKE SURE TO MODIFY BREADBOARD WIRING!!<-OK ORG 0000H LJMP MAIN ;DO JUMP TO AVOID GETTING A 'RET ASSEMBLY ERROR' ON PROGRAM STARTUP ORG 0003H ;STANDARD EXTERNAL INTERRUPT INT0 ENTRY POINT EXTINT0: MOV A,P0 SETB P3.7 ;HIGH TO LOW TRANSITION TO CLR INTERRUPT LINE AND ENABLE OUTPUT LATCHES CLR P3.7 ;NOTE: P3.7 = RD PIN ON 8051 MOV R5,#0FFH RETI ORG 0030H ;STANDARD MAIN PROGRAM ENTRY POINT (WHEN USING INTERRUPTS) MAIN: MOV SP,#256-32 MOV SCON,#01010000B MOV TMOD,#00100101B ;T1=MODE 2(8-BIT AUTO RELOAD MODE),TIMER MOV PCON,#10000000B ;TURN SMOD HIGH (DOUBLE BAUD) MOV TH1,#0FBH ;TH1 = 256 - ((Crystal / 192) / Baud) WHEN SMOD HIGH ;TH1 = 256 - ((18.432E6 / 192) / 19200 ) = 251 ;THEREFORE AT TH1=256 BAUD RATE = 19200 SETB IT0 ;SET IT0 IN TCON SFR TO MAKE INT0 -VE EDGE TRIGGERED <BE SURE> ;FIRST 8 ADCS (N0 TO N7) MOV A,#01111111B ;ENABLE N7 ADC MOV P2,#11111111B MOV R0,#1 SETB TR1 ;INITIALIZE TIMER1 N0N7: PUSH ACC MOV P1,A JNB P1.0,HERE JNB P1.1,HERE2 JNB P1.2,N5 JNB P1.3,N4 JNB P1.4,N3 JNB P1.5,N2 JNB P1.6,N1 JNB P1.7,N0 CONT: SETB P3.6 ;HIGH TO LOW PULSE TO ADC0804 WR PIN CLR P3.6 NOP NOP SETB P3.6 ;LOW TO HIGH PULSE TO ADC0804 WR PIN (START CONVERSION) MOV IE,#01H ;ENABLE EXTERNAL INTERRUPT (INT0) SETB EA ;ENABLE GLOBAL INTERRUPT BIT IN IE REGISTER (OR SFR) HERE5: CJNE R5,#0FFH,HERE5 CLR EA MOV R5,#00H LCALL TX_BYTE POP ACC RR A INC R0 CJNE R0,#9,N0N7 LCALL N8N9 LJMP N0N7 HERE: LJMP N7 HERE2: LJMP N6 N0: MOV A,#'N' CALL TX_BYTE MOV A,#'0' CALL TX_BYTE LJMP CONT N1: MOV A,#'N' CALL TX_BYTE MOV A,#'1' CALL TX_BYTE LJMP CONT N2: MOV A,#'N' CALL TX_BYTE MOV A,#'2' CALL TX_BYTE LJMP CONT N3: MOV A,#'N' CALL TX_BYTE MOV A,#'3' CALL TX_BYTE LJMP CONT N4: MOV A,#'N' CALL TX_BYTE MOV A,#'4' CALL TX_BYTE LJMP CONT N5: MOV A,#'N' CALL TX_BYTE MOV A,#'5' CALL TX_BYTE LJMP CONT N6: MOV A,#'N' CALL TX_BYTE MOV A,#'6' CALL TX_BYTE LJMP CONT N7: MOV A,#'N' CALL TX_BYTE MOV A,#'7' CALL TX_BYTE LJMP CONT N8: MOV A,#'N' CALL TX_BYTE MOV A,#'8' CALL TX_BYTE RET N9: MOV A,#'N' CALL TX_BYTE MOV A,#'9' CALL TX_BYTE RET N8N9: ;LAST 2 ADCS (N8 AND N9 MOV P1,#11111111B MOV P2,#01111111B LCALL N8 MOV A,P0 CALL TX_BYTE MOV P2,#10111111B LCALL N9 MOV A,P0 MOV A,#01111111B MOV P2,#11111111B MOV R0,#1 RET TX_BYTE: PUSH IE CLR TI MOV SBUF,A JNB TI,$ CLR TI POP IE RET END Thanks in advance for any help! Kai Busuttil Industrial Electronics Student |
Topic | Author | Date |
Check my External Interrupt code | 01/01/70 00:00 | |
new question about external interrupt code | 01/01/70 00:00 | |
Scarry Type ISR Programming | 01/01/70 00:00 | |
Problem solved...almost... | 01/01/70 00:00 | |
Bogus Interrupt Usage | 01/01/70 00:00 | |
An alternative to your solution? | 01/01/70 00:00 | |
set a trap and walk right into it![]() | 01/01/70 00:00 | |
A comment on comments | 01/01/70 00:00 |