| ??? 12/10/07 20:28 Read: times |
#148055 - More on the PWM program Responding to: ???'s previous message |
Hi Nima,
One of the reasons to write in assembly language rather than a high level language like C is to make your programs small and fast. Once you get your PWM program working properly, you might want to think about ways to optimize it. Sometimes you'll need to do this sort of thing for practical reasons. If you're a bit of a geek, you might also find that it's just plain fun. As an example, here's a snippet that works about the same as your program does, but with only eight instructions in the main loop:
MainLoop: CLR RI0 ; Acknowledge any recent Rx bytes
SETB LED ; Turn output on
StillOn: DEC A ; Count down from OnTime (in SBUF)
CJNE A,#0,StillOn ; to zero
CLR LED ; Turn output off
StillOff: DEC A ; Count down from 255 to OnTime
CJNE A,SBUF,StillOff ; (in SBUF)
JMP MainLoop ; Repeat forever
(Folks here are geeky enough that somebody will probably pop up and show how to do it with six instructions, or four :)
Here are a couple of other things to think about once you get your program working properly:
It would be interesting to know what you are doing. What made you want to generate a PWM signal in the first place? -- Russ |
| Topic | Author | Date |
| PWM code thoughts and help? | 01/01/70 00:00 | |
| Some thoughts and help | 01/01/70 00:00 | |
| very good help Russ | 01/01/70 00:00 | |
| cheers! | 01/01/70 00:00 | |
| character for 32 | 01/01/70 00:00 | |
| Good | 01/01/70 00:00 | |
| A & R4 fatal occurence | 01/01/70 00:00 | |
| Info on interrupts | 01/01/70 00:00 | |
| Right next to me... | 01/01/70 00:00 | |
| Aha | 01/01/70 00:00 | |
| tell the truth! | 01/01/70 00:00 | |
| Take a few deep breaths | 01/01/70 00:00 | |
| no arteries popping | 01/01/70 00:00 | |
| hows this? :) | 01/01/70 00:00 | |
| Better, but still has problems | 01/01/70 00:00 | |
| running out of subject line ideas | 01/01/70 00:00 | |
| re: running out of subject line ideas :) | 01/01/70 00:00 | |
| Some comments | 01/01/70 00:00 | |
| Interrupts and shared resources | 01/01/70 00:00 | |
| a thought - if it is help is up to you | 01/01/70 00:00 | |
| More on the PWM program | 01/01/70 00:00 | |
Purpose of my question | 01/01/70 00:00 |



