Digital Hexadecimal timer, problem displaying bits converted to segments...

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Digital Hexadecimal timer, problem displaying bits converted to segments...

1,102 Views
karmabobby
Contributor I
Code:
#include <hidef.h> /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */#define MASK_BITS1 0xF00 //Masks bits 11-8 on#define MASK_BITS2 0x0F0 //Masks bits 7-4 on#define MASK_BITS3 0x00F //Masks bits 3-0 on #define MASK_NIBBLE 0x0F // Masks buts 7-4 off #define DIGIT_PORT  PTFD     //Port F used for digits//#define DIGIT_MASK  0xF0     //Used to mask bits 7,6 and 5 in Port F//#define SEG_PORT    PTBD       // Port B used for segments //#define SEG_MASK    0x7F       //Used to mask Port B for correct output//#define Mask_Digits 0x03     //used to mask variable digits to 00000011// Function Prototypes //unsigned char NibbleToSegments(unsigned char);void delay(long int);void Output_Seven_Segments(unsigned char, unsigned char);void main(void);unsigned char NibbleToSegments (unsigned char nibble){  const byte Segment_Lookup[16] =   // Lookup table for hex numbers to segments on{    63,6,91,79,102,109,125,7,127,103,119,124,57,94,121,113}; nibble&=MASK_NIBBLE;  return Segment_Lookup[nibble];}   void delay(long int n){ long int i; unsigned int j; for (i=0; i<n; i++)   for (j=0; j<1000; j++)     {}}  void Output_Seven_Segments (unsigned char segments ,unsigned char digit){ //Remember: segments variable is formed as: //        DP g f e d c b a      digit &= Mask_Digits; //Mask variable digit to '00000011'      DIGIT_PORT &= ~DIGIT_MASK;  // Set all digits OFF //      SEG_PORT = segments & SEG_MASK;  //Port B assigned vairable segments      DIGIT_PORT = (0x80 >> digit);        // Turn on the proper digit}void main (void){   unsigned char segment;    unsigned int time;     EnableInterrupts; /* enable interrupts */  // Set DDRs for output ports   SOPT_COPE = 0;//Disable watchdog timer   PTADD = 0x02; // Replace XX with the hex value to set the PA2 and PA1 as outputs      PTFDD = 0xE0; // Same here, setting the inputs/outputs for port F   PTBDD = 0xFF; // Setting the input/outputs for Port B          time=0;        for (;;)  //Loop forever (as always!) {   time++;     segment=(time&MASK_BITS1);    NibbleToSegments(segment);    Output_Seven_Segments(segment,0);  //Convert to Segments and Output bits (11:8) of time  delay(1);        segment=(time&MASK_BITS2);    NibbleToSegments(segment);     Output_Seven_Segments(segment,1);  //Convert to Segments and Output bits (7:4) of time  delay(1);   segment=(time&MASK_BITS3);  NibbleToSegments(segment);    Output_Seven_Segments(segment,2);  //Convert ...  bits (3:0) of time  delay(1); }}

 
Ok, this is a digital hexadecimal timer I am currently working on. The code above is correct apart from one bug. The display doesn't pick up the values from the look up table. Its still just displaying each individual segment in some form of digital binary counter. Any suggestions as to what the problem is? I will also replace the delay with a timer subroutine but I know how to do that. The hex numbers are different for this as there is a manufacturing fault on the board so these are the correct values for this board.


Message Edited by karmabobby on 2008-04-24 11:02 AM
Labels (1)
0 Kudos
1 Reply

275 Views
allawtterb
Contributor IV
I haven't looked completely through the program but NibbleToSegments returns a value that you are not using, I think that you want to read this value into segment in,
 
Code:
segment = NibbleToSegment(segment);

 
0 Kudos