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

i need help on LED programming
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
love_hina
Guest







i need help on LED programming
PostPosted: Fri Jul 23, 2004 7:40 pm     Reply with quote

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.. Crying or Very sad
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Fri Jul 23, 2004 10:33 pm     Reply with quote

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
PostPosted: Sun Jul 25, 2004 7:02 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Sun Jul 25, 2004 7:31 pm     Reply with quote

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
PostPosted: Sun Jul 25, 2004 11:40 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 26, 2004 7:12 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 26, 2004 8:04 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jul 26, 2004 8:41 am     Reply with quote

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
PostPosted: Mon Jul 26, 2004 7:04 pm     Reply with quote

thanz a lot..i will go try it out first. Smile
love_hina
Guest







help help
PostPosted: Wed Jul 28, 2004 12:18 am     Reply with quote

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... Crying or Very sad
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Jul 28, 2004 6:11 am     Reply with quote

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
PostPosted: Wed Jul 28, 2004 7:08 pm     Reply with quote

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: 1912
Location: Norman, OK

View user's profile Send private message

PostPosted: Wed Jul 28, 2004 7:49 pm     Reply with quote

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

View user's profile Send private message

Re: re re
PostPosted: Wed Jul 28, 2004 7:49 pm     Reply with quote

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
PostPosted: Wed Jul 28, 2004 8:44 pm     Reply with quote

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.... Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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