??? 03/08/04 19:56 Read: times |
#66287 - RE: I think this should be okay Responding to: ???'s previous message |
I paid a little visit to your site to view the updated code, and I was a little disappointed that it does not show any signs of improvement after all the advice that was given to you in this thread.
Your main loop: LOOP: mov sbuf,@r0 ;move the content pointed by r0 to sbuf for transmission to PC nop ;just to pause SJMP LOOP - You definitely do not want to do this. This will cause what is at @r0 to be written to sbuf endlessly, and much, much too quickly. This is essentially the same as why your original code was never going to work. Also, WHY the nop? What good is that going to do you? The "pause" it will give you is 100 times shorter than the time it takes for a character to be transmitted at 9600 baud! You need: mov sbuf,@r0 LOOP: SJMP LOOP Then your isr: SERIAL: JNB TI,$ CLR TI cjne r0,#42h,next mov r0,#40h sjmp out next:inc r0 out:mov sbuf,@r0 RETI SERIAL: JNB TI,$ - You have not enabled your receiver, so the only thing leading to a serial interrupt will be TI. So every time you enter the isr, you will find TI set. Period. There is no sense in testing it, let alone starting a tight loop to poll it (which as I have pointed out before is a dirty, primitive technique anyway). As I pointed out before also, it makes no sense to do a combination of interrupt and polling the flag which caused the interrupt. So did you read that? Did you understand it? cjne r0,#42h,next mov r0,#40h sjmp out next:inc r0 out:mov sbuf,@r0 RETI - Can you tell when this sequence will stop once started? Well: never. It will endlessly start to transmit the characters without ever stopping. You don't want that, you want it to happen once, and then the transmissions must stop. So: inc r0 cjne r0,#43h,out reti out: mov sbuf,@r0 reti The code you showed in your "is this okay" post made me think you were somewhat on the right track, but this is a big step back. You are staring at the code too much and not trying to understand what is really happening. Throw your simulator in the bin, and start using your head. It is better. Another question relating to your seeing only junk characters in the terminal emulator: What frequency crystal are you using with your controller? |