ghostman11
Well-Known Member
it isnt finished yet but my 9 yr old wanted me to post what he has done so far
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.
unfortunately it dosnt look as neat on here as it does in mplab lol he has spent alot of time with the comments
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