Hi I'm driving some leds using bs170 mosfet. The led's are lighting up however I would like to be able to turn it off after 30 seconds say. I tried using the following code but it didn't work. I think it's turning off and on faster than I notice. I seem to be getting a square wave on the scope on the pin that the fet is connected to.
/*
* AVRGCC1.c
*
* Created: 21/04/2011 21:38:56
* Author: steven
*/
#define F_CPU 20000000UL // 1 MHz
#include <util/delay.h>
#include <avr/io.h>
int main(void)
{
//TODO:: Please write your application code
DDRA=0b00000001; //Make PDA0 as output
PORTA =0b00000001; // turn on fet
_delay_ms(30000);
DDRA=0b00000000;
}
Best Answer
This part ..
should probably look like this ..
i.e., you don't want to redefine the direction of the pin, you want to change its state.