#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
unsigned char Selected_Pattern=0;
unsigned char x=0;
const unsigned char Patterns[4][10] =
{
{0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF}, //"all on/off pattern"
{0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA}, //"chasing lights" pattern
{0x80,0x40,0x80,0x40,0x80,0x40,0x80,0x40,0x00,0x00}, //"Ping-pong" pattern
{0x01,0x05,0x56,0x79,0xAA,0x90,0x25,0x87,0x99,0xEE} //"My Pattern" Scrambled
};
//DELAY SUBROUTINE
void delay(long int n) {
long int i;
unsigned int j;
for (i=0; i<n; i++)
for (j=0; j<10000; j++)
{}
}
void main(void){
EnableInterrupts; /* enable interrupts */
/* include your code here */
SOPT_COPE = 0; //Disable the watchdog timer
PTFDD=0xff;
//const will store this in flash since it is not being modified
// 4 is the number of patterns and 10 is the length of all patterns
for(;
{
for (x=1;x<10;x++) {
if (PTAD==0) {
Selected_Pattern = Selected_Pattern++;
}
PTFD = Patterns[Selected_Pattern][x];
delay(1); //called delay subroutine
}
__RESET_WATCHDOG(); /* feeds the dog */
}/* loop forever */
/* please make sure that you never leave main */
}
PTAD is an active low push button. High when pressed down and low when up.
Heres some assembly code. I dont know how to increment the variable Selected_Pattern by one whenever the button is pressed in C. In my current program it simply cycles through the patterns, and when its changed to a one it does nothing.