beautypg.com

Texas Instruments MSP50C614 User Manual

Page 365

background image

Implementation Details

5-65

Code Development Tools

cmm_func

iport(int x); // read a port

int i,j,k,l;

// various temp and loop variables

int x[4];

// array holding the correct key sequence

int locked=1;

//variable returned by lock()

cmm_func lock(){

x[0]= 0xEF; //MS7
x[1]= 0xBF; //MS9
x[2]= 0xEF; //MS7
x[3]= 0x7F; //MS10

locked=0;
cport(’B’, 0xFF);

//Configure port B as output.
//Port B is the LED’s on the
//code development unit.

oport(’B’, 0xFF);

//Turn off all 4 LEDs.

for (i=0; i<4; i++){

// loop through all required inputs

k=iport(’F’); // read port F

while( k == 0xFF ){

// wait for keypress

k=iport(’F’);

// read port F

oport(’B’, k);

// output the value from F

wait(100);

// delay 100ms for key debouncing

}

l=iport(’F’);

// read port F

while( l != 0xFF ){

// wait for key release

wait(100);

// delay 100ms for key debouncing

l=iport(’F’);

// read port F

}

if (x[i] != k) {

// compare to correct input

locked=1;

// if incorrect then lock and return

return locked;

}

} // end for (i=0; i<4; i++){
return locked; // If the program reaches this return then all inputs were

correct

// and the main program can unlock.

}
cmm_func main() // code begins executing here after init614.asm is executed
{
asminit(); // configure everything

cport(’B’, 0xFF); //configure port B as output
for (j=0; j<1000; j++){ //semi–infinite loop
if (lock()){ // get input and see if correct
// if lock()==1 the input was incorrect

// The LED’s are then flashed and the program repeats.
oport(’B’, 0x00);
wait(100);
oport(’B’, 0xFF);
wait(100);
oport(’B’, 0x00);
wait(100);
oport(’B’, 0xFF);