Hi Guys,
This is the first time I have just started with Keil C .
Yet, I have no idea about this concept.
Please clarify it for me.
Thank you all.

#include <stdio.h>
#include "NUC1xx.h"
#include "Driver\DrvGPIO.h"
#include "Driver\DrvSYS.h"
#include "Seven_Segment.h"
#define SEG_N0   0x82 
#define SEG_N1   0xEE 
#define SEG_N2   0x07 
#define SEG_N3   0x46 
#define SEG_N4   0x6A  
#define SEG_N5   0x52 
#define SEG_N6   0x12 
#define SEG_N7   0xE6 
#define SEG_N8   0x02 
#define SEG_N9   0x62
#define SEG_N10  0x22
#define SEG_N11  0x1A
#define SEG_N12  0x93
#define SEG_N13  0x0E
#define SEG_N14  0x13
#define SEG_N15  0x33

unsigned char SEG_BUF[16]={SEG_N0, SEG_N1, SEG_N2, SEG_N3, SEG_N4, SEG_N5, SEG_N6, SEG_N7, SEG_N8, SEG_N9, SEG_N10, SEG_N11, SEG_N12, SEG_N13, SEG_N14, SEG_N15}; // this is an array of Heximal character from 0 to F.

void show_seven_segment(unsigned char no, unsigned char number)
    unsigned char temp,i;



***: could any one tell me how the loop works and why the condition is to do with 0x01

Thank you

Edited by coca99

3 Years
Discussion Span
Last Post by coca99

Hi coca99, welcome at Daniweb!
The loop tests the bits in temp by ANDing with 0x01 on line 32.
If this gives 0x01 than bit i of DrvGPIO is set, else it is cleared. The next bit of temp will be tested after a right shift by 1 on line 38.

Edited by ddanbe: addition


Thank ddanbe.
Yet, when I read the defined term in Hex, there are no value which related to 0x01 when we mention (==0x01). In addition, only the four-following define include (temp&0x01)==0x01.

define SEG_N2 0x07 (//7//0111)

define SEG_N12 0x93 (//147//10010011)

define SEG_N14 0x13 (//19//10011)

define SEG_N15 0x33 (//51//110011)

In my document, the led will set if we use ClearBit and vice versa. Thus, ostensibly I think (==0x01) is the range/condition out of the SEG_BUF.
However, with the four define above, the first binary value =1 so I still do not understand the term (temp&0x01)==0x01.

Please could you explain more detailed for me.

Thank you so much


Using 4 bits here to keep it simple
Say temp is equal to 0110 (=6 decimal)
0x01 I will represent by 0001

Anding will give:
& 0001
  0000 ---> not equal to 0001 so  DrvGPIO_ClrBit(E_GPE,i); is executed

Next we do a right shift of one and temp becomes 0011, after anding:
& 0001
  0001 ---> equal to 0001 so  DrvGPIO_SetBit(E_GPE,i); is executed 

And so on till the loop is finished.
Hope this makes it a bit(no pun intended) clearer.

Edited by ddanbe: correction

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.