electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

Using ADC n PWM to light up the LED dimmer - need help


Goto page Previous  1, 2, 3
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Using ADC n PWM to light up the LED dimmer - need help
Author Message
jason1987



Joined: 22 Jun 2009
Posts: 69
Location: japan


Post17 Jul 2009 8:35   

Re: i am doing ADC


i know that to measure is t use oscillograph but the problem is that i don't know how to write code.. reading datasheet is very big different compare to write a programming code and i don't know how to write. i facing problem is that i don't know how to generate PWM i have a code with mi.. take a look and give mi some guide. thank



#include <C8051F200.h> // SFR declarations

//-----------------------------------------------------------------------------
// Global Constants
//-----------------------------------------------------------------------------

#define SYSCLK 16000000/8 // SYSCLK in Hz (16 MHz internal
// oscillator / Cool
// the internal oscillator has a
// tolerance of +/- 20%

#define TIMER_PRESCALER 12 // Based on Timer CKCON settings

// There are SYSCLK/TIMER_PRESCALER timer ticks per second, so
// SYSCLK/TIMER_PRESCALER/1000 timer ticks per millisecond.
#define TIMER_TICKS_PER_MS SYSCLK/TIMER_PRESCALER/1000

// Note: TIMER_TICKS_PER_MS should not exceed 255 (0xFF) for the 8-bit timer

#define AUX1 TIMER_TICKS_PER_MS
#define AUX2 -AUX1

#define LED_TOGGLE_RATE 100 // LED toggle rate in milliseconds
// if LED_TOGGLE_RATE = 1, the LED will
// be on for 1 millisecond and off for
// 1 millisecond

#define TIMER0_RELOAD_HIGH AUX2 // Reload value for Timer0 high byte

sbit LED = P2^4; // LED='1' means ON
sbit pwm = P1^3;
//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------

void Port_Init (void); // Port initialization routine
void Timer0_Init (void); // Timer0 initialization routine

//-----------------------------------------------------------------------------
// main() Routine
//-----------------------------------------------------------------------------

unsigned int value;

void main (void)
{
WDTCN = 0xDE; // Disable watchdog timer
WDTCN = 0xAD;

Timer0_Init (); // Initialize the Timer0
Port_Init (); // Init Ports

EA = 1; // Enable global interrupts

while (1); // Loop forever
}

void Port_Init (void)
{
PRT2CF = 0x10; // Set LED to push-pull
}

void Timer0_Init(void)
{
TH0 = TIMER0_RELOAD_HIGH; // Reinit Timer0 High register
TL0 = TH0; // Set the intial Timer0 value

ET0 = 1; // Timer0 interrupt enabled
TMOD = 0x02; // 16-bit Mode Timer0
TCON = 0x10; // Timer0 ON
}


--
void Timer0_ISR (void) interrupt 1
{
static int counter = 0;

if((counter++) == LED_TOGGLE_RATE)
{
LED = ~LED; // Toggle the LED
pwm = ~pwm;
counter = 0;
}
}

//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Using ADC n PWM to light up the LED dimmer - need help
Page 3 of 3 All times are GMT + 1 Hour
Goto page Previous  1, 2, 3
Similar topics:
Light Dimmer using nec6122 IR protocol with pic12f629 (2)
Help Needed... Light dimmer (1)
Need help. led light circuit with output at on/off (4)
Light dimmer/brightner- need circuit to gradually bright,dim (2)
LED driver using PWM???? (2)
problem with counter using led matrix... why not light on? (2)
Light dimmer.... (8)
IR light dimmer (9)
Light Dimmer (2)
Remote Light dimmer (3)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS