Jump to content
Sign in to follow this  
vane

Can anyone help me?

Recommended Posts

I have made RC-Cam's landtastic and i wondered if there was any way someone could make like an example code filethat would show me the basics of using the signal wire of a radio control unit to do stuff so i could possibly make a little unit that plugs into a receiver then when you flick a switch it lights up an LED or something, i would love it if you could help me!!!

Peter

Share this post


Link to post
Share on other sites

It provides the HEX code, and it's a ppm input code I presume but not proportional output. You mentioned in your post that you wanted to light up an LED or something which is a binary output, not an analog output.

Share this post


Link to post
Share on other sites

i want to know how to code the hex, so i was reqesting if anyone would be so kind as to make me an example code so i could see what kind of layout it goes in etc etc

Share this post


Link to post
Share on other sites

Search for my latest posts, I know I posted an example in another thread lately.

Share this post


Link to post
Share on other sites

sorry im not too familliar with C, is there another source file with that?

#include <12F675.h>


// Camera has 2 lines for focus and shutter, 3.3V pulled down by 2-pos switch

#define Servo_in	PIN_A5 //PIN_A0

#define Focus_out	PIN_A1 //PIN_A4

#define	Shutter_out	PIN_A0 //PIN_A1


void main(void)

{

	ENABLE_INTERRUPTS(GLOBAL);

	ENABLE_INTERRUPTS(INT_RA5); // Pin state change interrupt on pin GP5

	port_a_pullups(0x20);


	while(1);

}


#INT_RA // Port state change interrupt

void servo_int(void)

{

	int16 Width=0;


	if(input(Servo_in)) // rising edge

		{

		SET_TIMER1(0);			

		SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_1);	//reset and start timer

		}

	else	// falling edge

		{

		SETUP_TIMER_1(T1_DISABLED);	//stop timer

		Width = GET_TIMER1();


		if(Width > 1333)

			output_low(Focus_out);

		else

			input(Focus_out);


		if(Width > 1666)

			output_low(Shutter_out);

		else

			input(Shutter_out);

		}


}

EDIT: ah, i think i understand, there is a .h file for all the different PICs with all the relevant inputs then you #include the one for the PIC you use, could you upload or link me to where i would be abkle to get them all? thanks

Edited by vane

Share this post


Link to post
Share on other sites

The .h file is specific to the compiler. If you install the same compiler as me (CCS PICC compiler), the headers will be installed at the same time and you'll be able to compile the code as it is here.

If you use another compiler, you might need to change that, maybe it won't even need a header, and you'll have to adapt the code a bit to its workings (the output_low(), SETUP_TIMER_1(), and other ENABLE_INTERRUPTS() might not exist in that compiler).

C in the microcontroller world is different to that in the PC world - on a PC all compilers will behave more or less the same and have all the same base standard built-in functions. In the microcontroller world all compilers are different, and the way each one requires you to code can differ a lot. For example if I was to port that code for another compiler I use now, I'd have to change all the function calls, because those who made that compiler didn't find worth it to include a level of abstraction for all those basic functions, so instead of writing a simple

ENABLE_INTERRUPTS(GLOBAL);

ENABLE_INTERRUPTS(INT_RA5);

that is device-independent, I would have to look at the datasheet of the specific PIC controller I'm using, find the registers that hold the bits that enables all interrupts and the pin change interrupt and set those bits to 1 directly at the lowest level, for example for a 12F675 with

INTCON.GIE=1; // global

INTCON.GPIE=1; // GPIO interrupt

IOC.5=1; //pin GP5

So my posting was obviously more of an example. The advantage of that compiler is that the very descriptive function names are close to pseudo-code, easy to understand without even commenting, so you should grasp the idea easily to reproduce it in the way your compiler will expect it.

Share this post


Link to post
Share on other sites

thanks for all the help, i'll try that :) could you link me to where i can download it?

Edited by vane

Share this post


Link to post
Share on other sites

http://www.ccsinfo.com/content.php?page=compilers

They have a 30-day demo. However after that the $350 would not make much sense just for hobby projects unless you really want to get deep into it...

An intermediate solution could be http://www.mikroe.com/en/compilers/mikroc/pic/

A bit cheaper at $250, and they have very good experimentation boards too. They have cheaper $150 compilers for other languages (basic and pascal) too.

There's still no free C compilers for PIC that I know of. If that's what you're looking for you'd better have a look at Atmel's AVRs.

Edited by Kilrah

Share this post


Link to post
Share on other sites

Oh, I see HI-TECH have released an unlimited free version of theirs which just lacks optimization, back when I tried it the free version had a pretty small code size limit that was too quickly reached.

http://microchip.htsoft.com/products/compi...ccpro-modes.php

That might suit you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×