#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Location
    sheffield
    Posts
    5
    Rep Power
    0

    lock in c++


    hello,
    my dad as set me this.

    at ome i have a Keil MCC2300 Development board.
    i am asking if anyone could help me. any help would be very nice, hopefully as i get better i will be able to help other people with some work.

    i am trying to design an electronic lock that is controlled by a single digital output bit ( 1 = locked, 0 = unlocked). The output is initially in the locked state. A predetermined 4-digit code entered in the correct sequence is required to open the lock.

    The code is to be entered using a variable voltage and a pushbutton:- A potentiometer will generate a voltage in the range 0 to +3.3v and this can be read via an ADC. The ADC reading can be scaled into a value, say, from 0 to 9 (or any other range if desired) and displayed in some way to the user. The number will be sampled when the pushbutton is pressed. This is to be repeated four times. If the correct four digit sequence is entered then the digital output will change to unlocked.
    Features to use of the LEDs, the serial port or preferably the LCD to aid the user; a timeout if the user takes to long to enter the code; a cancel or restart option (probably not needed if a timeout is implemented); use of the speaker to issue beeps etc.

    its a big question, sorry if not the right type of question for thsi forum

    thanks
    tim
  2. #2
  3. No Profile Picture
    Principal Goatkeeper
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Location
    Galway, Ireland
    Posts
    296
    Rep Power
    178
    Not really a programming question at all, let alone a C++ one, although you do need some programming to accomplish it. Good luck tho, and come back when you have a programming question !
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    886
    Wish I had time to go deep on this. Maybe tonight. For now, I have requested that this thread be moved to the Embedded Programming forum.
    I no longer wish to be associated with this site.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    886
    We should be able to assist you with this. What is your level of programming skills? Any experience in C or C++ or were you planning on coding in assembler?

    I did a quick search and did not turn up an MCC2300 dev board. Can you provide links to both your tool chain and the specific board? I am familiar with Keil and do not see an MCC2300 on their web site. Is this an old board?

    So it sounds like you are going to have to learn how to use an Analog to Digital Converter (ADC) effectively. How many bits of resolution do we have to work with? We need to know the specs on that potentiometer (aka; pot) as well as the value of the supply voltage. It sounds as if you're going to have lots of room to work with since 3.3v / 10 is 33mV and even an 8 bit ADC can resolve down to 3.3/256 or better than 12 uV, but if the pot is very noisy or non-linear, we could still have some issues.

    Generally for something like this you would ignore the ADC until the user presses the button, then you would take and average as many samples as you can without appearing to be unresponsive (maybe a seconds worth of data). At this point you have a digital value in some range that you need to convert to a number in the range of 0...9. A simple way to do that is with modulus arithmetic; which in your case could be as simple as dividing by 10 and discarding the remainder.

    What kind of processor do you have on that development board?
    I no longer wish to be associated with this site.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Location
    sheffield
    Posts
    5
    Rep Power
    0
    Originally Posted by jwdonahue

    What kind of processor do you have on that development board?
    hi, thankyou for the reply.

    im sorry i missed spelled the board name its a MCB2300 ARM processor board.

    im kinda new to c++, iv done simple things on the board, e.g. LED count on 8 leds, the most complicated one iv done is one that took me ages to figure out, its a simple sequencer such as a washing machine programme. the code i did for the washing machine thing is below, i just thought id show this to show i am trying learn c++ and not just wanting a quick answer to my problem.

    [PHPNET] LPC23xx Family Microprocessors
    *
    * The program continuously turns the 8 LEDs connected to Port 2 bits 0-7
    * on and off and outputs a message to the serial output using printf().

    ******************************************/
    #include <stdio.h>
    #include <LPC23xx.H> // LPC23xx definitions

    /* Declare user functions */
    void Port2_init(void);
    void delay(void);

    // Main program
    int main (void)
    {


    Port2_init();

    while((FIO2PIN & 0x00000001) == 0 ) //While bit 0 = 1 machine is on
    {
    ;
    }
    FIO2SET = 0x00000010; // Bit 4 = 1 Valve for cold water to come in

    while ((FIO2PIN & 0x00000002) == 0) //wait till Bit 1 = 1 Upper level switch
    {
    ;
    }
    FIO2CLR = 0x00000010; // Bit 4 = 0 Valve is turned off bec is full

    FIO2SET = 0x00000020; // Bit 5 = 1 heating the water

    while ((FIO2PIN & 0x00000004)== 0) //Bit 2 = 1 thermostat to turn off the heater
    {
    ;

    }
    FIO2CLR = 0x00000020; // Bit 5 = 0 heater off

    FIO2SET = 0x00000040; // Bit 6 = 1 Agitating washing
    delay();
    FIO2CLR = 0x00000040; // Bit 6 = 0 Stop agitating washing
    FIO2SET = 0x00000080; // Bit 7 = 1 Pump to empty the water
    while((FIO2PIN & 0x00000008)==0) // Wait till Bit 3 = 1 then turn off Bit 7 = 0 Pump off
    {
    ;
    }

    FIO2CLR = 0x00000080; // Bit 7 = 0 "pump turn off"
    while ((FIO2PIN & 0x00000001)!= 0) // Wait till bit 0 = 0 "Machine turn off"
    {
    ;
    }


    }


    /* User functions */

    void Port2_init(void) {
    PINSEL10 = 0; // Disable ETM interface, enable LEDs
    FIO2DIR = 0x000000F0; // P2.0..3 defined input and P2.4..7 as Outputs
    FIO2MASK = 0x00000000; // Unmask all Port bits
    }

    void delay(void )
    {

    int counter;
    for(counter = 0; counter < 1000000; counter++)
    {
    ; //do nothing
    }
    }[/PHPNET]

    i have the source files already done, i think thats what they area called, i just trying to figure out the acual code for making the door lock work.

    up to now iv done the arrays, (i think they are called that)
    this is what iv got so far on the door lock, its not very much but i can only do it when iv finished school and done my other homework.

    [PHPNET]int main (void)
    {

    int ADC0read; // converts pot value to digital

    int channel = 0; // to do with adc conversion

    int test_code[]; // test the input against the code

    int code[]={1,2,3,4}; // correct code

    char lcd_output[]; // output on lcd

    float pot_output[]; // potensiomater output[/PHPNET]

    sorry if post is too long, i just wanted to wright everything down befor i forgot hw to explain it properly.

    thankyou again for your help jwdonahue
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    886
    You used the wrong tags for your code. Try [ C O D E ] ... [ / C O D E ] instead (without the spaces)

    Code:
    int main (void)
     {
     
        int ADC0read;  //	 converts pot value to digital
     
        int channel = 0;	//	  to do with adc conversion
     
        int test_code[];   //	 test the input against the code
     
        int code[]={1,2,3,4};  //  correct code
     
        char lcd_output[];	  //	 output on lcd
     
        float pot_output[];
    }
    This code probably doesn't compile. test_code[] is an incomplete declaration. The compiler doesn't know how big the array should be. Same thing for lcd_output[] and pot_output[].
    I no longer wish to be associated with this site.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Location
    sheffield
    Posts
    5
    Rep Power
    0
    thanks very much for the help, iv changed the ones you pointed out for me.
    i havnt got very far at all from that point, im realy confused. im not sure how to start it or even how to continue it. iv been looking all over the net for some type of example of how to start it. im not sure if to use four while loops or FOR loop with a while loop in.

    any help would be fantastic, i hate it when i cant do something, im usualy learn better when iv got an answer and then from their figure out how the answer came about, well thats what i do in maths

    sorry if im being a nuisence, i just seem to of been doing this forever.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Location
    sheffield
    Posts
    5
    Rep Power
    0
    iv
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    May 2004
    Posts
    3,417
    Rep Power
    886
    Oh, sorry I missed this earlier. I've been pretty busy lately.

    Write down, in your native language, the basic algorithm(s) you need to use to accomplish what you want to do. You'll have to do some research in the docs on the board you are using to accomplish this. You may even find some simple examples of how to use the various sub-systems on whatever site supports your board. These might be hard to come by though if the board is particularly old.

    Don't get wrapped up in which kind of loop construct to use. The algorithm you describe for the problem should help you decide which one is best. If you get stuck, redefine the problem to reduce/eliminate the embedded systems aspects and post your question in the C/C++ forum where you'll get lots of good answers to well written language specific questions. Post your code there and ask whether a particular loop construct might be better than the one you have.

    Do read the C/C++ FAQ posted at the top of the C/C++ forum. You might find the answers you need there.

    http://forums.devshed.com/c-programm...ns-179036.html
    I no longer wish to be associated with this site.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Location
    sheffield
    Posts
    5
    Rep Power
    0
    thanks very much for the replys and help.

    i spent 12 hours yesterday on it and have manged to get it working quite well, iv got a fewsmall problems but should have them fixed today.

    thanks again for all your help jwdonahue

IMN logo majestic logo threadwatch logo seochat tools logo