|
|
View previous topic :: View next topic |
Author |
Message |
Kreg
Joined: 27 Aug 2014 Posts: 2
|
Rotate LED |
Posted: Wed Aug 27, 2014 2:55 am |
|
|
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
|
|
Posted: Wed Aug 27, 2014 3:06 am |
|
|
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
|
|
Posted: Wed Aug 27, 2014 1:33 pm |
|
|
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);
} |
|
|
|
|
|
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
|