Thread: Flashing LED Program

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    2

    Flashing LED Program

    Hi,

    I have got a development board with an 18F8722 on it. The bored comes with a built in LED for testing.
    I'm trying to write a program to flash the LED. I written a whole host of different programs and none of them work.
    The board has the LED connect to RH0 and in my code am using #define <htc.h> which contains the link to the pic18f8722 hex file which has the ports adress on it.
    Does anyone have any programs that are similar to this or knows how to write it because none of mine are working when I am wiring to the board.

    Jay

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    #define <htc.h>
    Are you really using #define, or was this just a typo? Because you almost certainly mean #include. #include is used when you want to include source from another file, #define is used for defining constants or macros.Try that and see if that changes anything.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Also you need to mention your OS.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Can you post the code you have written so far; is it in C or assembly?

  5. #5
    Registered User
    Join Date
    Feb 2010
    Posts
    2
    Yeh sorry I meant Include not define.

    This is the code that the seller of the boards has actually sent to me.
    Code:
    #include	<htc.h>
    
    void Delay(unsigned long cntr) {
    	while (--cntr != 0);
    }
    
    // main function
    void main( void ) {
    
    
    	INTCON 	= 0x0;			// Disable inerupt
    	CMCON 	= 0x07;		    	// Comparators Off
    	ADCON1  = 0x06;			// Port as Digital IO
    	TRISA0 	= 0;			// Led pin as output
    	CVRCON  = 0;
    
    
    	// loop forever - echo 
    	while(1) {
    
    		// Toggle led
    		RH0 ^= 1;
    		// Simple delay
    		Delay(50000);
    	}
    }

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Does the supplied program work on the board?

    > I written a whole host of different programs and none of them work.
    Programming at this level can be like that - don't worry too much.
    There is no safety net, and it takes no prisoners. You have to be very sure that what you have will work (rather than will probably work, but I've got a debugger to help).

    You need to start out with really small baby steps (say just change the frequency of the LED).
    Build up slowly at first.


    Does the board come with a host emulator?
    Such a thing would allow you to run your code on your PC, and probably give you some decent debug into the bargain.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM