Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

9 Yr old first project

Status
Not open for further replies.

ghostman11

Well-Known Member
it isnt finished yet but my 9 yr old wanted me to post what he has done so far :D many thanks to 3V0 who has been teaching us C ! and thats no easy task ;) as the project gets finished we will post all the details and some pictures. basicaly what we have done is mount 30 bicolour LEDs onto a CD then charlieplexed them to a pic 18f4685, actualy it looks alot cooler than it sounds and he is only nine!! 3v0 helped explain how functions work and arrays, the code is a long long way from finished but my boy is in a hurry to see what people think so far so i have posted it,
he has had limited help from me and considering he has only been attempting to program for a week or so i think he has done really well.

Code:
#pragma config OSC = IRCIO67, PWRT = OFF, WDT = OFF, MCLRE = ON, DEBUG = ON, LVP = OFF //..............Fuse stup
#include <p18f4685.h>
#include <stdio.h>
#include <delays.h>
//..........................................Single LED Defines Port A..............................

//                              H = High  L = Low x = Input
                                  
#define LED1RED 0    //************port A RA1 H RA0 L RA2 X
#define LED2RED 1    //************port A RA0 H RA1 L RA2 X
#define LED3RED 2   //*************port A RA2 L RA0 H RA1 X
#define LED4RED 6   //*************port A RA4 L RA3 H RA5 X      
#define LED5RED 7  //**************port A RA3 L RA4 H RA5 X
#define LED6RED 8 //***************port A RA2 L RA3 H RA4 X
#define LED1GREEN 3 //*************port A RA1 L RA2 H RA0 X
#define LED2GREEN 4 //*************port A RA0 L RA2 H RA1 X
#define LED3GREEN 5 //*************port A RA1 H RA2 L RA0 X
#define LED4GREEN 9 //*************port A RA4 L RA5 H RA3 X
#define LED5GREEN 10//*************port A RA3 L RA2 H RA4 X
#define LED6GREEN 11//*************port A RA5 L RA4 H RA3 X


//**********************Delay Set up***************************************************************************************************

#define Delay Delay10TCYx(10);
#define Delay1 Delay100TCYx(40);

//*************************************************************************************************************************************

//........................................................................Port Arrays...................................................

//                                                                        PORT A

//                  L1red     L2red     L3Red      L1Green    L2 Green   L3 Green   L4 Red     L5 Red     L6 Red     L4 Green   L5 Green   L6 Green
//                76543210   76543210   76543210   76543210   76543210   76543210   76543210   76543210   76543210   76543210   76543210   76543210
 char portaA[]={0b00000001,0b00000010,0b00000001,0b00000100,0b00000110,0b00000010,0b00001000,0b00010000,0b00001000,0b00100000,0b00100000,0b00010000,};               
 char trisaA[]={0b00000100,0b00000100,0b11111010,0b11111001,0b11111010,0b11111001,0b11100111,0b11100111,0b11010111,0b11001111,0b11010111,0b11001111,};
//                76543210   76543210   76543210   76543210   76543210   76543210   76543210   76543210   76543210   76543210   76543210   76543210

//.......................................................................................................................................




//******************************************Multi Led Arrays********************************************************

 char mlA[]={0b00000001,};   //Multiple Leds Port A
 char tmlA[]={0b00000100,}; // Multiple Leds Tris A
 
//******************************************************************************************************************


//......................................... PORT A Single Leds Function.............................................

 void ledA(unsigned char num)
 {
   TRISA=0b11111111;   // prevents ghosting
   PORTA=portaA[num];
   TRISA=trisaA[num];
}

//.................................................................................................................

//*******************************************Multi led port A Function*********************************************

void mla(unsigned char num)
 {
TRISA=0b11111111;   // prevents ghosting
   PORTA=mlA[num];
   TRISA=tmlA[num];
}

//****************************************************************************************************************



//=====================================================================================================================================
//=====================================================================================================================================
//**************************************************************Main Program***********************************************************
	
void main()
{

   	
   	ADCON1 = 0x0f;
	OSCCON = 0x7; //....Timer set internal 8MHz.....
	//while(1)
  
   {
	   
//.........................................LED Test Sequence............................................................................
   
    ledA(LED1RED);Delay1;ledA(LED1GREEN);Delay1;ledA(LED2RED);Delay1;ledA(LED2GREEN);Delay1;ledA(LED3RED);Delay1;ledA(LED3GREEN);Delay1;
    ledA(LED4RED);Delay1;ledA(LED4GREEN);Delay1;ledA(LED5RED);Delay1;ledA(LED5GREEN);Delay1;ledA(LED6RED);Delay1;ledA(LED6GREEN);Delay1;
    ledA(LED1RED);Delay;ledA(LED2RED);Delay;ledA(LED3RED);Delay;ledA(LED4RED);Delay;
   
   
//.........................................End Of Test Sequence.........................................................................
   }
}

unfortunately it dosnt look as neat on here as it does in mplab lol he has spent alot of time with the comments :D
 
Sounds like an interesting project, would be interesting to see some schematics and some pictures of the project so far.

Quite impressive for a 9 year old!

I see you are from Devon, i'm in Taunton.

Wilksey
 
Taunton then your vertualy up the road :D i will post schems and all the other stuff with pics soon as i get a chance. he has had a intersting idea for the case
 
Pretty much up the road yes!
Excellent, sounds like you're almost done with it!

Where do you get your electronic parts from? I'm trying to find some cheap LM1881N chips, but they are quite expensive on farnell, rs, etc. Especially with the postage.

Wilksey
 
heh i might have to copy and try this.. This is sweet!!! dude! Can you post a video when done? I just tought my 3 year old how to turn on my laptop and touchpad and mouse. He can turn it on , run a program, and maximize a window. all he does it watch tv on my PC heh..

I cant wait for him to get to your sons age and we can do something together like that. I think its a great job!! especially hes so young... I hope you guys can post a video when done. Would love to see it.... keep up the good work !!!
 
i get my parts from farnel or sometimes i have a mooch on ebay wilksey, thanks jason. we will deff post a video when its done wich hopefully will be by the weekend. we chose it because there is a fair bit we can learn with it. once we are a bit more adept he wants to add pwm effects etc.
 
I might look into setting up an account with RS or somewhere then, they offer free postage if you set up an account, but I am not sure on their T+C's.

I look frequently on EBay, they can be more expensive than distributors sometimes though!

Ahh, PWM, I had terrible trouble using PWM from a 18f4520 on a 8x8 sign board, row + column driven, half the LED's wouldn't light up etc as it was trying to draw too much current from the PIC.

The easiest way I found was to use transistors to drive and sink the current to / from the pic, and use a PWM signal from the PIC with a 5v signal going into an AND gate to drive the gate of the FET transistor. I could have used a darlington, but the FET's served my purpose better.

I'm not sure of your circuit, but I had to also put a 1MR resistor across the source and drain to get the transistor to switch off at an instant rate, may have just been the 20 yr old transistors I was using at the time though :)

Wilksey
 
i get my parts from farnel or sometimes i have a mooch on ebay wilksey, thanks jason. we will deff post a video when its done wich hopefully will be by the weekend. we chose it because there is a fair bit we can learn with it. once we are a bit more adept he wants to add pwm effects etc.

Nice job!

I might be able to help him with PWM on Charlieplexed LEDs. I'm currently doin' 9-bit (512 step) PWM on a 20 LED matrix with a 390-Hz refresh rate. If I were to expand that demo' to a 6-pin 30 LED matrix I could still get 9-bit (512 step) resolution but the refresh rate would go down to about 325-Hz.

Kind regards, Mike
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top