Texas Instruments MSP50C614 manual Implementation Details

Models: MSP50C614

1 414
Download 414 pages 24.44 Kb
Page 365
Image 365

 

Implementation Details

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);

Code Development Tools

5-65

Page 365
Image 365
Texas Instruments MSP50C614 manual Implementation Details