Daryl Hurst

C problem with HCS08 starter kit. - Added p/n to subject.

Discussion created by Daryl Hurst on Mar 6, 2008
Latest reply on Mar 13, 2008 by Jim Donelson
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
 
 

  #include <MC9S08GB60.h>
  //This file contains a large number of symbol
  //definitions, so we can use names such as
  //PTFD instead of the real address which is 0x0040.
  //You can open the file to see what symbols are defined.
  
 

//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++)
     {}
    
}
 
//MAIN PROGRAM
void main (void)
{
 unsigned char count=0;
 unsigned char x=0;
 

//case statement to determine which pattern is being shown
 

switch (PTAD)
{
If (PTAD<0x04);
 {
 PTAD = PTAD && 0x01;
 }
 If (PTAD=0x04);
  {
  PTAD = 0x00;
  }

  case 1: PTAD = 0x00;
// Pattern 1 (all on/off)
 for (x=1; x<=9; x++)
 {
  
    if (x==1) {PTFD=0x00;}
    if (x==2) {PTFD=0xff;}
    if (x==3) {PTFD=0x00;}
    if (x==4) {PTFD=0xff;}
    if (x==4) {PTFD=0x00;}
    if (x==5) {PTFD=0xff;}
    if (x==6) {PTFD=0x00;}
    if (x==7) {PTFD=0xff;}
    if (x==8) {PTFD=0x00;}
    if (x==9) {PTFD=0xff;}
 }
 break;
 
  case 2: PTAD = 0x01;
//Pattern 2 (Chasing Lights)
 for (x=1; x<=9; x++)
 {
  
    if (x==1) {PTFD=0x55;} 
    if (x==2) {PTFD=0xAA;} 
    if (x==3) {PTFD=0x55;} 
    if (x==4) {PTFD=0xAA;} 
    if (x==4) {PTFD=0x55;} 
    if (x==5) {PTFD=0xAA;}
    if (x==6) {PTFD=0x55;} 
    if (x==7) {PTFD=0xAA;} 
    if (x==8) {PTFD=0x55;} 
    if (x==9) {PTFD=0xAA;}
 }
  break;
 
  case 3: PTAD = 0x02;
//Pattern 3 (Ping-Pong Lights)
 for (x=1; x<=8; x++)
 {
  
    if (x==1) {PTFD=0x80;}  
    if (x==2) {PTFD=0x40;}  
    if (x==3) {PTFD=0x20;}  
    if (x==4) {PTFD=0x10;}  
    if (x==4) {PTFD=0x08;}  
    if (x==5) {PTFD=0x04;}  
    if (x==6) {PTFD=0x02;}  
    if (x==7) {PTFD=0x01;}  
    if (x==8) {PTFD=0x00;}  
 }
 break;
 
  case 4: PTAD = 0x03;
//Pattern 4(My Pattern)
 for (x=1; x<=9; x++)
 {
  
    if (x==1) {PTFD=0x01;}  
    if (x==2) {PTFD=0x05;}  
    if (x==3) {PTFD=0x56;}  
    if (x==4) {PTFD=0x79;}  
    if (x==4) {PTFD=0xAA;}  
    if (x==5) {PTFD=0x90;}  
    if (x==6) {PTFD=0x25;}  
    if (x==7) {PTFD=0x87;}  
    if (x==8) {PTFD=0x99;}  
    if (x==9) {PTFD=0xEE;}  
 }
 break;
}
 SOPT_COPE = 0; //Disable the watchdog timer
 PTFDD=0xff; //What does this line do?

 
 for (;:smileywink: //Loop forever.  You should NEVER exit main!
   {
   
    PTFD =  ; //Output to PORTF
    count++; //a counter which is increased here
    delay(1); //And delay some time here.
   }
}

The code above is part of an assignment I have been given on my course. I have to have PTFD flash in different patterns whenever the button(PTAD) has been pressed. There is a delay sub routine and a switch statement in the program. I have decided to increment PTAD by anding it with hex (01) as this will increment by one. I am having problems getting the output displayed, Im pretty new at C and I think I have done an Ok job with my code. If anyone can spot any major mistakes and/or help me make this program more efficient and help me sort out this output problem I would be very grateful.
 
I also need to link the frequency of the output to the A2D converter. What would be the best way to do this? I have thought about this and thought having the A2D variable linked with the size of the delay loop variable seems like a valid idea. However I am new and as you may well know that a lot of ideas you come up with dont necessarily work
 
 
 
 
 
 
Added p/n to subject.
 
 


Message Edited by NLFSJ on 2008-03-10 03:12 PM

Outcomes