free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Rickey's World :: Discussion Forums :: Discuss and Learn :: 8051 Discussion Forum
 
<< Previous thread | Next thread >>
help mi
Moderators: Ajay Bhargav, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph, ExperimenterUK, DavesGarage
Author Post
jason1987
Mon Jun 29 2009, 07:57PM
 User Offline
Registered Member #19032
Joined: Wed Jun 03 2009, 08:28PM

Posts: 27
Thanked 0 times in 0 posts
what does the following code do?

CODE:
#include<c8051f200.h> //
//definitions
sbit LED = P2^4;

void adc_init(); //to initialize adc
void port_init(); //to initialize the ports

void main()
{

unsigned int index=0, total_period= (unsigned int) 255*256, on_time=0;
port_init();
adc_init();


   // disable watchdog timer
   WDTCN = 0xde;
   WDTCN = 0xad;

   
    {
        ADBUSY = 0x01;                          //starts the adc conversion
        while(ADCINT);                            //polling for ADCINT which tells us the end of conversion
        ADCINT = 0x00;
        on_time = ((unsigned int)ADC0H)*256;
        for ( index = 0 ; index < total_period ; index++)
        {
            if (on_time--)
            {
                LED = 0x01; //switching on the LED
                       
            }

            else
            {
                LED = 0x00; //switching off the LED
            }
        }
    }  
}

void adc_init ()

{
    AMX0SL = 0x3f;                         // enable AMUX & configure for p3.7 as i/p pin
    ADC0CF = 0x60;                         // set conversion clk at one sys clk and PGA at gain =1
    ADC0CN = 0xC0;                         // ADC is enabled and ADBUSY=0 (changed here)
    REF0CN = 0x03;                         // VDD is selected as Vref. Here are you using VDD for variable resistor also?
}
void port_init()
{
    P3MODE = 0X7F;                   // Except the P3.7 pin all are configured as digital I/O
}
 




[ Edited Fri Jul 03 2009, 04:54AM ]

aaaa

Back to top

tcs89
Tue Jun 30 2009, 02:18AM
 User Offline
Registered Member #19683
Joined: Thu Jun 25 2009, 06:49PM

Posts: 2
Thanked 0 times in 0 posts
help help
Back to top

Ajay Bhargav
Fri Jul 03 2009, 05:02AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 7567
Thanked 1331 times in 1255 posts
looks like its a PWM code.

you have on time defined by ADC and off time is total_period - ontime

[Topic moved to 8051 Discussion forum]

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top

 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems