CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Other Programming > Assembly
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Assembly Questions and Answers for Assembly here!

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old October 24th, 2004, 12:08 AM
    hkboy313 hkboy313 is offline
    Junior Member
     
    Join Date: Oct 2004
    Posts: 17
    hkboy313 is an unknown quantity at this point (<10)
    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...
    Reply With Quote
      #2    
    Old October 26th, 2004, 03:34 AM
    bigBA's Avatar
    bigBA bigBA is offline
    Member +
     
    Join Date: May 2004
    Location: Germany
    Posts: 649
    bigBA is a jewel in the rough (200+)bigBA is a jewel in the rough (200+)bigBA is a jewel in the rough (200+)
    Re: How do I combine an ASM program with a C program

    Quote:
    Originally Posted by hkboy313
    #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
    }

    }
    if it is what you want, your code is ok. - but you really should do it in another way

    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 you have to set the according interrupt service register for that timer (i had to do it with the c167... so i don't know if it is the same with the 8051, but i think so)

    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/
    Reply With Quote
      #3    
    Old October 28th, 2004, 12:53 PM
    hkboy313 hkboy313 is offline
    Junior Member
     
    Join Date: Oct 2004
    Posts: 17
    hkboy313 is an unknown quantity at this point (<10)
    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
    Reply With Quote
      #4    
    Old October 29th, 2004, 03:12 AM
    bigBA's Avatar
    bigBA bigBA is offline
    Member +
     
    Join Date: May 2004
    Location: Germany
    Posts: 649
    bigBA is a jewel in the rough (200+)bigBA is a jewel in the rough (200+)bigBA is a jewel in the rough (200+)
    Talking Re: How do I combine an ASM program with a C program

    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/
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Other Programming > Assembly


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 08:54 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009