Hello Amit,
Simply breaking up the previous code into several files does not help in making your code more understandable.
Assembly code is never "self-documenting". It generally needs copious comments within the code to understand its operation. This is in the context of what you are attempting to achieve, and the details of achieving this aim, rather than merely describing the operation of an instruction.
As a simple example, I would not expect that any RTS instruction would need a comment unless the sub-routine contained more than one RTS and a specific exit condition at this point was important to the operation of the calling code.
It should not be necessary to re-examine the datasheet for the MCU to derive the initialisation conditions for a peripheral register - an added comment should summarize the setting. An instruction like BSET 0,PTAD is meaningless withou a comment. Yes, we know that bit-0 of PTA output register is being set, but what does bit-0 do? Far more meaningful would be: BSET RLY,PTAD ; Activate relay
where RLY has previously been defined by an equate.
nova0809 wrote:One thing that I will like to add , by reading all of your comments I had just disconnected the lcd module & checked if my code section was OK. But the MCU is still resetting.
I don’t kno y???
I did not see within your code where you were clearing the COP timer, to prevent a COP reset. However, I could not specifically identify your main loop structure where it would usually be placed. Delay routines that may exceed the COP timeout period will also need to clear the COP timer. A macro is often used for this purpose.
nova0809 wrote:
I am not attaching the remote control decoding section. If any one wants then I will attach it as it is very lengthy. I am also requesting for any suggestion to simplify my remote control decoding section. At presently I am using the internal CLK of MC9S08SE8 is 5MHZ & creating several loops to match the delaying pulse of NEC protocol & it’s a very lengthy process. Can any one suggest any easier process by using the MC9S08SE8 MCU?????
Using software delay loops for this type of application, as you seem to be suggesting, can work satisfactorily, and need not require lengthy code. The method is best suited to simple applications where the MCU is mainly idle until an IR transmission is received.
The process that I have used makes use of two very similar subroutines to analyse the incoming pulse train from the IR receiver module. Both provide a variable timeout period. The WAITHIGH routine waits until either a high input state, or timeout occurs. The exit condition will determine the next step for the decoding process. The second routine is WAITLOW, which waits until either a low input state, or timeout occurs. Both routines are also designed to ignore very short transient pulses, i.e. less than 100 us.
I have typically used an incremental delay value of 10-20 us, depending on the bus frequency, with the required delay determined by an 8-bit value. This gives a maximum delay value in the vicinity of 2500 - 5000 us. I would then call these routines using macros, so that the delay can be expressed directly in microseconds. The closest (rounded) 8-bit value for the required delay is calculated within the macro during the assembly process.
Actually this method may prove awkward because of a large disparity of timing periods within the NEC protocol, particularly with the start pulse period of 9000 us.
It should also be feasible to make use of a TPM channel operating with input capture mode. The use an interrupt will allow other tasks to occur during the IR receive process. Since the NEC protocol uses pulse-position modulation (PPM) following the start pulse and first gap, the pulse width is not really of interest, only the total period between successive pulses determines the current bit state. You will probably need a prescale division ration of 4, or more. A division ratio of 4 will give a timing resolution of 0.8 microseconds, which is more than adequate.
Regards,
Mac