View previous topic :: View next topic |
Author |
Message |
love_hina Guest
|
i need help on LED programming |
Posted: Fri Jul 23, 2004 7:40 pm |
|
|
hi to all..i need urgent help on programmin PIC18f252. using visual basic, user can enter the data to turn on the 7 LED lights on the board. eg. 1 will light up 1st light...etc. the problem is i do not know how to do it..i am a newbie in this and have try different ways but it doesn't work. i'm using MPLAB IDE v6.40.. pls help me..thanz a lot.. |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Fri Jul 23, 2004 10:33 pm |
|
|
Which part of the project is giving you trouble? Getting the PIC to talk to VB? Or flashing the LEDs?
Give us more information, and post your code. |
|
|
love_hina Guest
|
re |
Posted: Sun Jul 25, 2004 7:02 pm |
|
|
i was not able to compile the program. it seems to have error...
#include <p18f252.h>
#include <timers.h>
#define NUMBER_OF_LEDS 7
void timer_isr (void);
static unsigned char s_count = 0;
#pragma code low_vector=0x18
void low_interrupt (void)
{
_asm GOTO timer_isr _endasm
}
#pragma code
#pragma interruptlow timer_isr save=PROD
void timer_isr (void)
{
static unsigned char led_display = 0;
INTCONbits.TMR0IF = 0;
s_count = s_count % (NUMBER_OF_LEDS + 1);
led_display = (1 << s_count++) - 1;
PORTB = led_display;
}
void
main (void)
{
TRISB = 0;
PORTB = 0;
OpenTimer0 (TIMER_INT_ON & T0_SOURCE_INT & T0_16BIT);
INTCONbits.GIE = 1;
while (1)
{
}
} |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Jul 25, 2004 7:31 pm |
|
|
Well your biggest problem if you are using CCS is that it appears the program was written for the Microchip C18 compiler |
|
|
love_hina Guest
|
re |
Posted: Sun Jul 25, 2004 11:40 pm |
|
|
yap..i got the program as i did not know wat to write..so i used it as a guide. my teacher in charge told me to do this.. right now i'm trying to modify but i dunno where to start.. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Jul 26, 2004 7:12 am |
|
|
Start REALLY simple!
Try a program that just blinks one LED. Something like:
Initialize ports
while (1) {
toggle LED
delay 1 second
}
Translating pseudo code to runnable C is left as an excercise for the student ;-)
Once that works try lighting a string of LEDS in sequence.
Next blink an LED whenever anything comes in the serial port.
Then try your original programming problem. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Jul 26, 2004 8:04 am |
|
|
You will have to look at the CCS manual. There are some samples there that will show you how to setup the fuses. Take a look at the interrupts. CCS does this much simpler. Look at the setup_timer functions instead of the C18 open_timer fuctions. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Jul 26, 2004 8:41 am |
|
|
For his simple problem I would suggest polling might be simpler than interrupts. Just keep polling kbhit() then use getch() when kbhit() returns true. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
love_hina Guest
|
thanz |
Posted: Mon Jul 26, 2004 7:04 pm |
|
|
thanz a lot..i will go try it out first. |
|
|
love_hina Guest
|
help help |
Posted: Wed Jul 28, 2004 12:18 am |
|
|
does anyone out there have the source code for lighting up LED?or u know of any webby tt has examples??i'm stuck on my project and need some sample..thanz a lot...
my program consists of lighting up LED by taking the input from what the user has key in from Visual basic. if the user key in 0,none of the LED will light up, if he key in 15, alternate lights will light up.. if reset button is pushed,all the lights will light up. i'm using RS232 for the link to visual basic and now i'm compiling for microcomputer. if u know of any web,pls help me..as time is pushing and i'm still having problems with my board..
thanz a lot... |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Jul 28, 2004 6:11 am |
|
|
You didn't describe you circuit or tell us was demo board you are using. Also post you code that you are trying. The previous code is not an example of what you are trying to do. People will help here but they are not going to do the work for you. |
|
|
love_hina Guest
|
re re |
Posted: Wed Jul 28, 2004 7:08 pm |
|
|
i'm jus asking if anyone has code sample for me to refer to. the board is done by me..7 LEDs , pic18f252, max232, RJ45 and db9con.... plus a few risistors and capacitors |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Wed Jul 28, 2004 7:49 pm |
|
|
ChingBs post immediatly after mine made mine irrellevant so I deleted it...
Oh Well...
Last edited by dyeatman on Wed Jul 28, 2004 7:52 pm; edited 2 times in total |
|
|
chingB
Joined: 29 Dec 2003 Posts: 81
|
Re: re re |
Posted: Wed Jul 28, 2004 7:49 pm |
|
|
love_hina wrote: | i'm jus asking if anyone has code sample for me to refer to. the board is done by me..7 LEDs , pic18f252, max232, RJ45 and db9con.... plus a few risistors and capacitors |
Code: |
#if defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
//#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7, enable=PIN_A1)
#endif
void main() {
do {
delay_ms(1000);
output_high(PIN_A0);
delay_ms(1000);
output_low(PIN_A0);
} while (TRUE);
}
|
|
|
|
love_hina Guest
|
re re |
Posted: Wed Jul 28, 2004 8:44 pm |
|
|
thanz a lot to both of you..hee..but i'm still blur..i go test it out first then i ask you more about the code..thanz a lot.... |
|
|
|