controlled running light

LED Blinking, Walking with Cytron Servo, Displaying RFID, Multi-function Mobile Robot......

controlled running light

Postby zulaikha » Mon Sep 10, 2012 11:34 am

hye all
i am new here,my name is zulaikha n i am a student
now i just start study pic in my uni..n i am trying to do blinking led.
i googling for the sourcecode n o found this
CODE: SELECT_ALL_CODE
-----------------------------------------------------------------------------------------------------------------------------
// PIC16F877A LED Blinking      
//===============================================================

//device definition header file
#include <htc.h>

//device configuration bit
__CONFIG(0x3F3A);

//define
#define LED1   RB7
#define LED2   RB6

//function prototype
void blink_LED1(unsigned char n);
void blink_LED2(unsigned char n);

//main function
//================================================================
void main(void)
{
   //device peripheral configuration
   TRISB7=0;      //set RB7 as output
   TRISB6=0;      //set RB6 as output
   
   //infinity loop
   while(1)
   {
      //blink LED1 for 3 times
      blink_LED1(3);
      
      //blink LED2 for 3 times
      blink_LED2(3);
   }
}

//function to blink LED1 for n times
void blink_LED1(unsigned char n)
{
   //loop for n times
   for(n+=1;n>0;n-=1)
   {
      //set LED1 to 1
      LED1=1;
      
      //short delay
      for(unsigned int i=0;i<20000;i+=1);    //max value is 65535
         
      //set LED1 to 1
      LED1=0;
      
      //short delay
      for(unsigned int i=0;i<20000;i+=1);    //max value is 65535         
   }   
}

//function to blink LED2 for n times
void blink_LED2(unsigned char n)
{
   //loop for n times
   for(n+=1;n>0;n-=1)
   {
      //set LED2 to 1
      LED2=1;
      
      //short delay
      for(unsigned int i=0;i<20000;i+=1);    //max value is 65535
         
      //set LED2 to 1
      LED2=0;
      
      //short delay
      for(unsigned int i=0;i<20000;i+=1);    //max value is 65535         
   }      
}      
---------------------------------------------------------------------------------------------------------------------

what i understand from the prgram is blink 2 led for 3 times.this is sound really basic for u but for me it is new world! :lol:
now i want to modified the program..iam going to used variable capsitor so that i can controlled the speed of led blinking.
i want to make running light that we can controlled the speed of their "running"..for the first time,i want to use 2 led.
can anyone help me plzz..if u can show which part must me added..it really help me..
User avatar
zulaikha
Freshie
 
Posts: 5
Joined: Mon Sep 10, 2012 11:14 am

Re: controlled running light

Postby shahrul » Mon Sep 10, 2012 2:31 pm

Like this you understand?
CODE: SELECT_ALL_CODE
for(;;){
value=read_a2d(0); //read analog input
LED1=1;
LED2=0;
for(i=0;i<value;i++) __delay_ms(1);
LED1=0;
LED2=1;
for(i=0;i<value;i++) __delay_ms(1);
}
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: controlled running light

Postby zulaikha » Mon Sep 10, 2012 2:52 pm

shahrul WROTE:Like this you understand?
CODE: SELECT_ALL_CODE
for(;;){
value=read_a2d(0); //read analog input
LED1=1;
LED2=0;
for(i=0;i<value;i++) __delay_ms(1);
LED1=0;
LED2=1;
for(i=0;i<value;i++) __delay_ms(1);
}


sorry mr shahrul i dunt get it..

value=read_a2d(0); //read analog input----------->this is for what ?

sorry i really new to this..im using variable resistor to control the led speed...what do i must put in the source code huh?let say im using 2 led for my learning...

if u can attach full of the source code its really hepl me
User avatar
zulaikha
Freshie
 
Posts: 5
Joined: Mon Sep 10, 2012 11:14 am

Re: controlled running light

Postby shahrul » Mon Sep 10, 2012 4:10 pm

Variable resistor will give analog value. Then PIC can read analog value. read_a2d(0) is my function to read analog.
This is my full ADC function.
CODE: SELECT_ALL_CODE
   int read_a2d(unsigned char channel)
   {
   #if defined (_16F877A)
      ADCON0=0b00000001;
      ADCON1=0b10000000;
      ADCON0=(ADCON0&0xC7)|(channel<<3);
   #elif defined (_16F886) || (_16F887)
      ADCON0=0b00000001;
      ADCON1=0b10000000;
      if(channel<=7) ANSEL=ANSEL|(0b00000001<<channel);
      else ANSELH=ANSELH|(0b00000001<<(channel-8));
      ADCON0=(ADCON0&0xC3)|(channel<<2);
   #elif defined (_18F2550) || (_18F4550)
      ADCON0=0b00000001;
      ADCON1=0b00000111;                  
      ADCON2=0b10000110;
      ADCON0=(ADCON0&0xC3)|(channel<<2);
   #endif
   __delay_ms(2);
   #if defined (_16F877A) || (_16F886) || (_16F887)
      GO=1;
      while(GO==1) continue;
   #elif defined (_18F2550) || (_18F4550)
      GODONE=1;
      while(GODONE==1) continue;
   #endif
   return(256*ADRESH+ADRESL);
   }

Example ADC here, Lesson ADC.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: controlled running light

Postby zulaikha » Mon Sep 10, 2012 4:22 pm

tq mr shahrul
i will study more on that n try it on board
User avatar
zulaikha
Freshie
 
Posts: 5
Joined: Mon Sep 10, 2012 11:14 am

Re: controlled running light

Postby yonghui » Tue Sep 11, 2012 10:48 am

i think your project does not need variable capacitor , instead variable resistor. PIC can read the analog value from the potentiometer to get voltage from the voltage divider. blink speed can be change with delays which depends on the voltage from the divider.
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: controlled running light

Postby hyng » Tue Sep 11, 2012 1:47 pm

For beginner, i hope the tutorial below will be helpful.
http://tutorial.cytron.com.my/2011/08/05/sk40c-tutorial/
User avatar
hyng
Moderator
 
Posts: 292
Joined: Thu Apr 16, 2009 11:35 am

Re: controlled running light

Postby zulaikha » Wed Sep 12, 2012 1:47 pm

tq very super mod hyng.
hope u guys can guide me tru this learning.
my email is mrsdealova7@yahoo.com
User avatar
zulaikha
Freshie
 
Posts: 5
Joined: Mon Sep 10, 2012 11:14 am


Return to DIY Project Set

Who is online

Users browsing this forum: No registered users and 12 guests

cron