Hi,
So, knock on wood, me and my partner finished our Traffic Lights program for school this last week. We used assembly code. The knock on wood part is that we did not use a timer as we didn't have time for trial and error to get it right so our second consist of:
sec1 mov #0004h,R13 ;Load 4 sec1_3 mov #0CDFAh,R12 ;Load 1/4 a second sec1_2 dec R12 ;Decrement by 1 clrz ;Clear Z Flag for JNZ to work cmp R12,R4 ;Did the timer reach 0? jnz sec1_2 ;Jump to decrement fast timer dec R13 ;Decrement R13 by 1 clrz ;Clear Z Flag for JNZ to work cmp R13,R4 ;Did R13 reach zero jnz sec1_3 ;Jump to fast timer Load ret ;Return from Stack
This is my partner's updated version to try and work out 1 second and 1.5 second problem we were having. (1/4 is easier to scale up to 1.5 then what we originally had).
He mainly wrote the program and i pointed out mistakes for this one because I mainly wrote or figured out our last project (and this community was a big help here). He was doing quite a few calculations when it came down to a second on the msp430G2553. He emailed me last night the final code version he wrote (he called it a mess), so my question is:
Doing it OUR WAY did he calculate 1/4 a second correctly? Or what would be 1 second so I could technically split it down to 1/4 or 1/2 second? Answering any one question (1/4s, 1/2s, 1s) would get me an answer I would like, but not need as of now. He was wracking his brain with new job and this so I thought I could possibly get him a solid answer.
I would have thought this would simple be a frequency divided (16Mhz) by 16bit (0FFFFh) question, but considering what he has above almost or does = 1 second I would be wrong.
I UNDERSTAND a timer would have been the better way, please don't berate us on this.