Hi all I have no coding experience but a friend helped me very fast to write a piece of code, he said would do the job i want to be done with my core module. I'll post it here just to show, I'm not sure it's perfectly correct but that's not my problem. I don't know how to get this code onto the 18f4685. As I'm not coding myself the world of compilers and files seems huge. I've tried to play around in MPLAB, sdcc skeleton, using example programs etc, but I'm not getting very close. I figured i need to include some mios files, a pic file? (452 only choice?) but how, where, more precise. short said i need some kinda step by step help to make this code a working hex :) I'm into learning C so if i knew how to get code going with the MIOS i could go learning from there. I know it's a pretty big question but also advice leading in the right direction is much appreciated! As you can see (i guess :)), the code is supposed to output a bunch of data which i´ll connect to several shift registers and then LED´s giving one LED for each button on a digital piano, via MIDI. Im posting the code mostly because it might be funnier for you coders ^^ Thank You
#include "cmios.h"
#include "pic18f452.h"
#define BIT_CLOCK 0
#define BIT_LATCH 1
#define BIT_DATA 2
#define CHANNEL 1
#define NOTEON 0x90
#define NOTEOFF 0x80
#define NOTE_OFFSET 15
#define BITASSIGN( bit, val ) PORTA = ( PORTA & ~( 1 << bit ) ) | ( val << bit );
unsigned char min( unsigned char a, unsigned char b )
{
return a < b ? a : b;
}
unsigned char buffer[ 11 ];
void Init( )
{
TRISA &= ~( ( 1 << BIT_CLOCK ) | ( 1 << BIT_LATCH ) | ( 1 << BIT_DATA ) );
}
void Delay( )
{
int i=0;
for( i; i<1000; ++i );
}
void ShiftBits( )
{
BITASSIGN( BIT_CLOCK, 1 );
Delay( );
BITASSIGN( BIT_CLOCK, 0 );
}
void LatchRegisters( )
{
BITASSIGN( BIT_LATCH, 1 );
Delay( );
BITASSIGN( BIT_LATCH, 0 );
}
void UpdateLeds( )
{
unsigned char j=0;
unsigned char bit=0;
for( j; j<11; ++j )
for( bit; bit<8; ++bit )
{
BITASSIGN( BIT_DATA, ( buffer[ j ] >> bit ) & 1 );
ShiftBits( );
}
LatchRegisters( );
}
void OnNoteOn( unsigned char note )
{
buffer[ note >> 3 ] |= 1 << ( note & 7 );
UpdateLeds( );
}
void OnNoteOff( unsigned char note )
{
buffer[ note >> 3 ] &= ~( 1 << ( note & 7 ) );
UpdateLeds( );
}
void USER_MPROC_NotifyReceivedEvent( unsigned char evnt0, unsigned char evnt1, unsigned char evnt2 )
{
if( ( ( NOTEOFF | CHANNEL ) == evnt0 ) || ( ( ( NOTEON | CHANNEL ) == evnt0 ) && ( 0 == evnt2 ) ) )
OnNoteOff( min( 0x6C, evnt1 - NOTE_OFFSET ) );
else if( ( NOTEON | CHANNEL ) == evnt0 )
OnNoteOn( min( 0x6C, evnt1 - NOTE_OFFSET ) );
}