Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Manual SN74LS165

Status
Not open for further replies.
Thanks a bunch. im going to save this as PDF.

[embed]http://www.youtube.com/v/_kRk1u9oN9M&hl[/embed]

I cant wait to get a better camera lol. Im using a crap web cam. When i get my good camera i will make videos and take pictures like crazy
 
Last edited:
hi,
Looks promising.

How have you named the 4 buttons.?
 
heh you got me. they are just hex right now but i plan to :
Code:
#define setupBtn  0x08
#define downBtn   0x02
#define upBtn     0x01
#define selectBtn 0x10

The alarm button is obsolete now :D since i made a it menu.

EDIT:
I just edited the code to use names instead of hex. Thx for reminder lol it will make is simpler.
 
Last edited:
hi,
I have a similar setup.

Menu, Inc, Dec, Accept.

Pressing the Menu pb steps thru the settings options.
When the required option is displayed, press the Accept.

eg: if it was the Date: the 'days' value is underlined and I use the Inc/Dec pb.
Once its the 'days' I want, press the Accept and it moves to the 'months' and so on... As soon as I press the Accept the DATE is written to tthe DS1307.

The same applies to the TIME.

If I start editing the DATE or TIME and I change my mind before pressing Accept, if I press the 'Menu' it exits the setting without changing the DATE/TIME. [like an escape pb]

In the 'normal' mode of operation, when I'm not setting the DATE/TIME if I press the 'Inc' pb, it displays the current TIME for 5 seconds.
If I press the 'Dec' pb it displays the DATE for 5 seconds.

Pressing the 'Accept' pb it displays the Temperature for 5 seconds.

Hope you can follow this OK.:)
 
nice setup! i understand. I have mines like when you press menu it shows the menu then you can press up or down to go through the list. Then Enter/Select to select it then it will ask you seperate items. Mainly because i caught a headache doing it for the time.

When i set the time it shows the time and you can press up/down and set it while seeing the whole thing. Including the am/pm.

Its cool. Thanks for the info on how yours is. I know you must have caugt a headache when first making it. I might rewrite my whole code since i learned so much now. But ill keep my menu type. Like up/down to scroll instead of Menu a few times to pick. I like being able to go back and forth . :)
 
nice setup! i understand. I have mines like when you press menu it shows the menu then you can press up or down to go through the list. Then Enter/Select to select it then it will ask you seperate items. Mainly because i caught a headache doing it for the time.

When i set the time it shows the time and you can press up/down and set it while seeing the whole thing. Including the am/pm.

Its cool. Thanks for the info on how yours is. I know you must have caugt a headache when first making it. I might rewrite my whole code since i learned so much now. But ill keep my menu type. Like up/down to scroll instead of Menu a few times to pick. I like being able to go back and forth . :)

Another handy feature is to have a 'factory settings' option.

Keeping the Menu pb down while powering up, takes you into a factory set mode or sets up defaults.
 
Nice. I still cant use timers to save my life. Well i can but hate to really just because of interrupts. I dont like timer interrupts. It gets confusing at times. This code i use have no interrupts at all.
 
Eric i thought you might like to see the new ShowMenu code:
Code:
/***********************************
LCD / RTC stuff
************************************
Show Menu
************************************/
void showMenu(void){
    char item, isEnter;
    isEnter = 0;
    item = 1;   //Default to first menu item

while(1){
/******************************
    Which item are we viewing
*******************************/
    switch(item){
        case 0:
            item=3; //user went do down too far start from 3
            break;
        case 1:
            sprintf(string2,"1.Set Time      ",0);
            break;
        case 2:
            sprintf(string2,"2.Set Date      ",0);
            break;
        case 3:
            sprintf(string2,"3.Set Alarm     ",0);
            break;
        case 4:
            item=1; //user went too up far start them from 1
            break;
    }
        
/*****************************
    Determine Button Pressed
******************************/
    switch(readBtn()){
        case upBtn:
            item++;
            break;
        case downBtn:
            item--;
            break;
        case selectBtn:
            isEnter = 1;
            break;
    }
/*****************************
    Enter is pressed
******************************/
    if(isEnter == 1){
        if(item==1)
            setTime('t');

        if(item==2){
            setDate();
        }
        if(item==3){
            //Set Alarm
        }

        item=9; //a overkill number incase i want to add more functions.
    }
/*************************
    Show Menu to the user
**************************/
    lcd_line(1);
    sprintf(string,"    Settings    ",0);
    lcd_string(&string);

    lcd_line(2);
    lcd_string(&string2);
/**************************
    Check if user is done.
***************************/
    if(item==9)
        break; //leave while(1) loop

}//end of while loop
}
 
Hey eric i was looking at your code and noticed:

Code:
tens = ShiftRight(tens, 4)

would that be equal to
Code:
tens >>=4;
 
Last edited:
Hey this is what i have for my BCD to Decimal code so since i got lost in the other one:
Code:
unsigned char bcd2dec(unsigned char aBCD, char type)
{
    char lowNyb = aBCD & 0x0F;
    char highNyb = aBCD >> 4;
    char MyDec = lowNyb;
    char x;

    switch(type)
        case 0:
            highNyb &= 0x0F;
            break;
        case 1:
            highNyb &= 0x01;
            break;
        case 2:
            highNyb &= 0x03;
            break;
        case 3:
            highNyb &= 0x07;
            break;
    }

    for(x=0;x<highNyb;x++){
        MyDec += 10;    
    }

    return MyDec;
}

the type feature is useful for RTC like the DS1306 and others... what is does is depending on the actual byte of BCD it may need less info for correct number like look at the hour field:

rtca-png.24799


The upper nybble only has 1 usable bit which is #4. The others (7:5) isnt usefull when converting from BCD to DECIMAL. The other info like AM/PM and 12/24 is extracted from another part of the program so its ok to toss it out here.

When you set it to 0 nothing changes. All are intact
When you set it to 1 it leaves the last digit intact and sets the rest to 0.
when you set it to 2 it leaves bits 0 & 1 intact and sets bits 2 & 3 to 0
when you set it to 3 it leaves bits 0,1,2 intact and sets bit 3 to 0

Nice heh.
 

Attachments

  • rtca.png
    rtca.png
    6.9 KB · Views: 167
Here is the code working:
Code:
/************************************
Convert BCD to Char(byte)
************************************/
unsigned char bcd2dec(unsigned char aBCD, char type)
{
    char lowNyb = aBCD & 0x0F;
    char highNyb = aBCD >> 4;
    char MyDec = lowNyb;
    char x;

    switch(type){
        case 0:
            highNyb &= 0x0F;
            break;
        case 1:
            highNyb &= 0x01;
            break;
        case 2:
            highNyb &= 0x03;
            break;
        case 3:
            highNyb &= 0x07;
            break;
    }

    for(x=0;x<highNyb;x++){
        MyDec += 10;    
    }

    return MyDec;
}

the ouput:( i the actual input is BCD but its in a tmp var and is overwritten alot. So i cant show it here. i did it that way to save space)
Below shows the BCD split in 2 for LCD display and the BCD converted to decimal using my function.
Code:
 Address  Symbol Name        Value        Hex  Decimal  Binary    Char 

   09A   theHour                     "09"                              
   09A   [0]                          '0' 0x30      48  00110000    '0'
   09B   [1]                          '9' 0x39      57  00111001    '9'

   09C   theMin                      "01"                              
   09C   [0]                          '0' 0x30      48  00110000    '0'
   09D   [1]                          '1' 0x31      49  00110001    '1'

   09E   theSec                      "34"                              
   09E   [0]                          '3' 0x33      51  00110011    '3'
   09F   [1]                          '4' 0x34      52  00110100    '4'
--------------------------------------------------------------------------
After the:
    decSec = bcd2dec(decSec,3);
    decMin = bcd2dec(decMin,3);
    decHour = bcd2dec(decHour,1);

   0A0   decHour                     0x09 0x09       9  00001001    '.'

   0A1   decMin                      0x01 0x01       1  00000001    '.'

   0A2   decSec                      0x22 0x22      34  00100010    '"'
 
hi atom.

would that be equal to tens >>=4; Yes
I posted the routines in Basic, as I use assembler and you use 'C', I thought Basic would provide a better explanation than assembler.

Ref the Hours, I use the 24 hour format.
 
i notice that :D ... i know your the more experienced here but you should save my code for your use also. I bet it may come in handy one day lol :D
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top