CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Rotate LED

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Kreg



Joined: 27 Aug 2014
Posts: 2

View user's profile Send private message

Rotate LED
PostPosted: Wed Aug 27, 2014 2:55 am     Reply with quote

Hi all !

I would like to ask a question.
Actually, I have just bought a PICKIT3 with a 18F45K20
I would like to 'flash and rotate' LED.

Can you help me ? I am a beginner.

All my LEDs are connected to the port D (there is 7 LED)

I would like to introduce an array of the form

const int LED_LookupTable[8]={0,1,2,3,4,5,6,7};

Then, sending the led_data in sequence to portD will light each each LED in turn.

Here is my code but it doesn't work :


Code:
/**  I  N  C  L  U  D  E  S  **************************************************/
#include  <18F45K20.h>
#FUSES INTRC_IO,NOWDT,NOLVP
#USE delay (CLOCK=1MHz)



#WORD LATD=0xF8C
#WORD PORTD=0xF83
#BIT led=LATD.0
#BIT led1=LATD.1
#BIT led2=LATD.2
#BIT led3=LATD.3
#BIT led4=LATD.4
#BIT led5=LATD.5
#BIT led6=LATD.6
#BIT led7=LATD.7



const int LED_LookupTable[8]={0,1,2,3,4,5,6,7};



void main(){
   int LED_Number=0;
   SET_TRIS_D(0b00000000);
   led7.LED_LookupTable[LED_Number];
   led7=1;
   LED_Number++;
   
   if(LED_Number==8){
      LED_Number=0;
   }   
   delay_ms(2000);

}


And the error about led7=1;
Quote:
Expecting a structure/union


How can I fix that ?

Thanks
Kreg



Joined: 27 Aug 2014
Posts: 2

View user's profile Send private message

PostPosted: Wed Aug 27, 2014 3:06 am     Reply with quote

Code:
/**  I  N  C  L  U  D  E  S  **************************************************/
#include  <18F45K20.h>
#FUSES INTRC_IO,NOWDT,NOLVP
#USE delay (CLOCK=1MHz)



#WORD LATD=0xF8C
#WORD PORTD=0xF83
#BIT led=LATD.0
#BIT led1=LATD.1
#BIT led2=LATD.2
#BIT led3=LATD.3
#BIT led4=LATD.4
#BIT led5=LATD.5
#BIT led6=LATD.6
#BIT led7=LATD.7



const int LED_LookupTable[8]={0,1,2,3,4,5,6,7};



void main(){
   LATD=0;
   int LED_Number=0;
   SET_TRIS_D(0b00000000);

   int i=0;

while(1){

   for(i=0;i<8;i++){
      bit_set(LATD,i);
      delay_ms(1000);
   }
   i=0;
   LATD=0;

}

}


This code works but I don't use the array unfortunately
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 27, 2014 1:33 pm     Reply with quote

This code lights up LEDs on PortB, bits 0 to 3. They are turned on
sequentially. Once turned on, the Leds stay on. This program
shows how to read from an array. I used PortB because that's the
way my hardware board is setup.
Code:

#include <18F452.h>
#fuses XT, BROWNOUT, PUT, NOWDT, NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

 int LED_LookupTable[8]={0,1,2,3,4,5,6,7};

#byte PORTB = getenv("SFR:PORTB")

//===================================
void main()
{
int i;

output_b(0x00);  // All Leds off initially, and PortB TRIS = all outputs

for(i = 0; i < 4; i++)
   {
    bit_set(PORTB, LED_LookupTable[i]);
    delay_ms(500);
   }

while(1);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group