| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Assembly Questions and Answers for Assembly here! |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How do I combine an ASM program with a C program
i am a noob ...im taking an embedded class and i have a lab that wants me to generate a square wave signal...well i got the time period which is 200 microsec. and 50% duty cycle is 100 microsec. crystal freq is 22.183 with that i got FF47 for the value (I think) that will go into the timer register.
with that given...and that i calculated...i programmed something at least... #include <8051io.h> #include <8051bit.h> /* Bit set/clear macros */ #include <8051reg.h> void main() { serinit(9600); asm { MOV TMOD,#01 HERE: MOV TL0,#047H MOV TH0,#0FFH CPL P1.5 ACALL DELAY SJMP HERE DELAY: SETB TR0 AGAIN: JNB TF0, AGAIN CLR TR0 CLR TF0 RET } } i know its kinda stupid to do that but...i saw an example on the program i used...micro-ide ...u can find the 8051 program at www.bipom.com butu need the hardware stuff to download program. i cannot compile this bcause i think of the asm language inside that prg. well my question is if im on the right track or total lost.... or in the asm above do i have to have the input in binary with "#%"? this is really confusing..its not even in our book! "The 8051 Microcontroller and embedded system" by muhammad ali mazidi and anice mazidi... sorry for long explanations...just had a couple concerns i wanted to get helped on. thanks so much in advance... |
|
#2
|
||||
|
||||
|
Re: How do I combine an ASM program with a C program
Quote:
![]() if you can work in c, then why don't you use it? a MOV TMOD, #01 is the same as writing TMOD = 1; in c! you can do that, because your are including some header files, and there the registers and port bits and so on are defined. so one other thing: how you generate the signal on P1.5 is, yeah... its ok. (but is P1.5 a output-only pin? if no - please set it explicitly to output before, otherwise it will maybe set initially to input, and you won't see any signal on the outside) generation of the signal... you could do it better with a interrupt service routine (ISR): in main: set up the timer and let it run, then you have to code an infinite loop like this: while(1); because otherwise the controller will continue trying to execute the opcodes in the memory, and that can, yeah it will, lead to undefined behavior. back to that isr. don't know how to code it for the 8051, but for the C167 i would do it (somehow, can't well remember) this way: Code:
void timer0_isr() interrupt = 0xXX
{
TL0 = 0x47;
TH0 = 0xFF;
P1.5 = !P1.5;
}
and now, every time the timer overflows, it will generate an interrupt. this will lead the controller to call the ISR. in it you reload the timer and toggle the output pin... and you have your signal. hope i could help you a little bit!
__________________
there are 10 kinds of people. those who understand binary and those who don't... rate a post if you find it usefull, thx check out my Firefox/Mozilla Extension: http://urlparams.blogwart.com/ |
|
#3
|
|||
|
|||
|
Re: How do I combine an ASM program with a C program
hey, thanks so much on the help, i finally got the program and it was similar to it too! kinda weird but ya
|
|
#4
|
||||
|
||||
|
you're welcome!
__________________
there are 10 kinds of people. those who understand binary and those who don't... rate a post if you find it usefull, thx check out my Firefox/Mozilla Extension: http://urlparams.blogwart.com/ |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|