Broun Hall Access System Weekly Status Report Week 7 PowerPoint PPT Presentation

presentation player overlay
1 / 16
About This Presentation
Transcript and Presenter's Notes

Title: Broun Hall Access System Weekly Status Report Week 7


1
Broun Hall Access SystemWeekly Status Report
Week 7
  • Janus Security
  • Brad Austin
  • Cole Brown
  • Kelly Hall
  • Kyle Coker
  • Russell Biser
  • Steve Hawkins
  • Linda Kirk

2
Outline
  • Introduction
  • Previous Accomplishments
  • Goals for the Week
  • Team Reports
  • Goals for Next Week
  • Conclusion
  • Questions

3
Introduction
  • Two project boards and transciever modules were
    wired in accordance with schematic
  • Code to interface with and test keypads was
    written for microcontroller
  • Database access software to confirm user
    authorized was written
  • Pulse width modulation code for the
    microcontroller buzzer interface written

4
Previous Accomplishments
  • Researched alternatives
  • Submitted project proposal
  • Selected and ordered components
  • Analyzed datasheets for all components
  • Began work on database tables and code
  • Connected the keypad and display
  • Downloaded code to the microcontroller
  • Designed data entry forms for the database

5
Goals for the week
  • Successfully test hardware for one door (working
    LCD, keypad)
  • Continue programming microcontroller
  • Use pulse-width-modulation (PWM) to regulate
    buzzer sound
  • Continue work coding the database

6
Timeline
7
Hardware
  • Updated Schematics due to pin conflicts
  • Wired three transcievers and two project board
    with displays and keypads. Yet to wire database
    side microcontroller kit
  • Coded interface between keypad and
    microcontroller
  • PWM for buzzer programmed

8
Schematic
Schematic changes to allow for serial
communication
9
Keypad
/ Keypad Scanner Author Steven Hawkins
Editor Cole Brown This programs scans a
keypad displays the binary value of the key
pressed to the LEDs. / include lthidef.hgt //
common defines and macros include
ltmc9s12c32.hgt // derivative information pragma
LINK_INFO DERIVATIVE "mc9s12c32" byte
keypressed43 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
0x0C // Function declarations void
display(int myrow, int mycolumn) void
scanColumn(int rownum2) void debounce() int
readRow() void main(void) //
EnableInterrupts / NOTE
Writing a 0 to bit y of DDRx sets bit y of Port x
to input. Writing a 1 to bit y of DDRx sets
bit y of Port x to output. WIRING NOTES
(are no longer right...) LEDs
LED1Pin13PTT(0), LED2Pin15PTT(1),
LED3Pin30PTT(2), LED4Pin32PTT(3),
LED5Pin34PTT(4), LED6Pin36PTT(5),
LED7Pin38PTT(6), LED8Pin40PTT(7)
KEYPAD Row1123Pin19PM2,
Row2456Pin23PM3, Row3789Pin17PM4,
Row40Pin21PM5 Col1147Pin7PS0,
Col22580Pin5PS1, Col3369Pin18PAD0
/ // set port T to output DDRT 0xFF PERT
0x00 // no pullup MODRR 0x00 // route pins
to port T RDRT 0x00 // full strength drive
// set port M to input //DDRM 0x00 //PERM
0x00 // disable pullup/pulldown //WOMM
0x00 // disable wired-or behavior, enable
push-pull output // set port S to
output //DDRS 0xFF //RDRS 0x00 // full
drive strength //PERS 0x00 // disable
pullup/pulldown //WOMS 0x00 // disable
wired-ord behavior, enable push-pull output //
set port AD to output DDRAD 0x87 RDRAD
0x00 PERAD 0x00 // Turn off LEDs PTT
0x00 // Write column 0 low 1 high //PTS
0xFC //PTAD 0x00 / NOTE Reading a
1 from a bit connected to a SW on the MCU means
the button is not pressed. Reading a 0 from
a bit connected to a SW on the MCU means the
button is pressed. / // Loop forever. for
() int rownum int colnum for(colnum
0 colnum lt 2 colnum) scanColumn(coln
um) rownum readRow() if(rownum !
-1) debounce() rownum
readRow() display(rownum, colnum) break
// quits outta column scan for loop //
end scanning columns // end forever // end
main // scanColumn // Parameters // int
colnum The column currently being scanned. //
Returns // void void scanColumn(int
colnum) if(colnum 0) PTAD_PTAD0
0x00 PTAD_PTAD1 0x01 PTAD_PTAD2
0x01 //PTS 0xFE else if(colnum
1) PTAD_PTAD0 0x01 PTAD_PTAD1
0x00 PTAD_PTAD2 0x01 //PTS
0xFD else if(colnum 2) PTAD_PTAD0
0x01 PTAD_PTAD1 0x01 PTAD_PTAD2
0x00 // end scanColumn function //
readRow // Parameters // none // Returns //
void int readRow() // Mask
PTAD. switch(PTAD 0x78) // No break
statements needed in these cases because we're
returning // straight outta the function from
each. case 0x70 return 0 case
0x68 return 1 case 0x58 return
2 case 0x38 return 3 default // No row
pressed. return -1 // end readRow
function // debounce // Short do-nothing for
loop to debounce switch. Increase upper //
bound of for loop if switches are not debouncing
properly. // Parameters // none //
Returns // void void debounce() int
i for(i 0 i lt 1000 i) // do nothing
loop // end debounce function // display //
Currently throws compiler warning about
"Possible loss of data". // This is due to PTT
taking in a byte while keypressed is an int, //
which is 4 bytes. EDIT Should be fixed, I hope.
Changed keypressed // to type "byte". //
This function sends data to PTT. //
Parameters // int myrow Row of the key that
is pressed. // int mycolumn Column of the key
that is pressed. // Returns // void void
display(int myrow, int mycolumn) // "-1"s are
due to the array being start-at-0 while the
keypad // row/column scan functions are
start-at-1. // Not no more. GUAH! PTT
keypressedmyrowmycolumn
/ Keypad Scanner Author Steven Hawkins
Editor Cole Brown This programs scans a
keypad displays the binary value of the key
pressed to the LEDs. / include lthidef.hgt //
common defines and macros include
ltmc9s12c32.hgt // derivative information pragma
LINK_INFO DERIVATIVE "mc9s12c32" byte
keypressed43 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
0x0C // Function declarations void
display(int myrow, int mycolumn) void
scanColumn(int rownum2) void debounce() int
readRow() void main(void) //
EnableInterrupts / NOTE
Writing a 0 to bit y of DDRx sets bit y of Port x
to input. Writing a 1 to bit y of DDRx sets
bit y of Port x to output. WIRING NOTES
(are no longer right...) LEDs
LED1Pin13PTT(0), LED2Pin15PTT(1),
LED3Pin30PTT(2), LED4Pin32PTT(3),
LED5Pin34PTT(4), LED6Pin36PTT(5),
LED7Pin38PTT(6), LED8Pin40PTT(7)
KEYPAD Row1123Pin19PM2,
Row2456Pin23PM3, Row3789Pin17PM4,
Row40Pin21PM5 Col1147Pin7PS0,
Col22580Pin5PS1, Col3369Pin18PAD0
/ // set port T to output DDRT 0xFF PERT
0x00 // no pullup MODRR 0x00 // route pins
to port T RDRT 0x00 // full strength drive
// set port M to input //DDRM 0x00 //PERM
0x00 // disable pullup/pulldown //WOMM
0x00 // disable wired-or behavior, enable
push-pull output // set port S to
output //DDRS 0xFF //RDRS 0x00 // full
drive strength //PERS 0x00 // disable
pullup/pulldown //WOMS 0x00 // disable
wired-ord behavior, enable push-pull output //
set port AD to output DDRAD 0x87 RDRAD
0x00 PERAD 0x00 // Turn off LEDs PTT
0x00 // Write column 0 low 1 high //PTS
0xFC //PTAD 0x00 / NOTE Reading a
1 from a bit connected to a SW on the MCU means
the button is not pressed. Reading a 0 from
a bit connected to a SW on the MCU means the
button is pressed. / // Loop forever. for
() int rownum int colnum for(colnum
0 colnum lt 2 colnum) scanColumn(coln
um) rownum readRow() if(rownum !
-1) debounce() rownum
readRow() display(rownum, colnum) break
// quits outta column scan for loop //
end scanning columns // end forever // end
main // scanColumn // Parameters // int
colnum The column currently being scanned. //
Returns // void void scanColumn(int
colnum) if(colnum 0) PTAD_PTAD0
0x00 PTAD_PTAD1 0x01 PTAD_PTAD2
0x01 //PTS 0xFE else if(colnum
1) PTAD_PTAD0 0x01 PTAD_PTAD1
0x00 PTAD_PTAD2 0x01 //PTS
0xFD else if(colnum 2) PTAD_PTAD0
0x01 PTAD_PTAD1 0x01 PTAD_PTAD2
0x00 // end scanColumn function //
readRow // Parameters // none // Returns //
void int readRow() // Mask
PTAD. switch(PTAD 0x78) // No break
statements needed in these cases because we're
returning // straight outta the function from
each. case 0x70 return 0 case
0x68 return 1 case 0x58 return
2 case 0x38 return 3 default // No row
pressed. return -1 // end readRow
function // debounce // Short do-nothing for
loop to debounce switch. Increase upper //
bound of for loop if switches are not debouncing
properly. // Parameters // none //
Returns // void void debounce() int
i for(i 0 i lt 1000 i) // do nothing
loop // end debounce function // display //
Currently throws compiler warning about
"Possible loss of data". // This is due to PTT
taking in a byte while keypressed is an int, //
which is 4 bytes. EDIT Should be fixed, I hope.
Changed keypressed // to type "byte". //
This function sends data to PTT. //
Parameters // int myrow Row of the key that
is pressed. // int mycolumn Column of the key
that is pressed. // Returns // void void
display(int myrow, int mycolumn) // "-1"s are
due to the array being start-at-0 while the
keypad // row/column scan functions are
start-at-1. // Not no more. GUAH! PTT
keypressedmyrowmycolumn
/ Keypad Scanner Author Steven Hawkins
Editor Cole Brown This programs scans a
keypad displays the binary value of the key
pressed to the LEDs. / include lthidef.hgt //
common defines and macros include
ltmc9s12c32.hgt // derivative information pragma
LINK_INFO DERIVATIVE "mc9s12c32" byte
keypressed43 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
0x0C // Function declarations void
display(int myrow, int mycolumn) void
scanColumn(int rownum2) void debounce() int
readRow() void main(void) //
EnableInterrupts / NOTE
Writing a 0 to bit y of DDRx sets bit y of Port x
to input. Writing a 1 to bit y of DDRx sets
bit y of Port x to output. WIRING NOTES
(are no longer right...) LEDs
LED1Pin13PTT(0), LED2Pin15PTT(1),
LED3Pin30PTT(2), LED4Pin32PTT(3),
LED5Pin34PTT(4), LED6Pin36PTT(5),
LED7Pin38PTT(6), LED8Pin40PTT(7)
KEYPAD Row1123Pin19PM2,
Row2456Pin23PM3, Row3789Pin17PM4,
Row40Pin21PM5 Col1147Pin7PS0,
Col22580Pin5PS1, Col3369Pin18PAD0
/ // set port T to output DDRT 0xFF PERT
0x00 // no pullup MODRR 0x00 // route pins
to port T RDRT 0x00 // full strength drive
// set port M to input //DDRM 0x00 //PERM
0x00 // disable pullup/pulldown //WOMM
0x00 // disable wired-or behavior, enable
push-pull output // set port S to
output //DDRS 0xFF //RDRS 0x00 // full
drive strength //PERS 0x00 // disable
pullup/pulldown //WOMS 0x00 // disable
wired-ord behavior, enable push-pull output //
set port AD to output DDRAD 0x87 RDRAD
0x00 PERAD 0x00 // Turn off LEDs PTT
0x00 // Write column 0 low 1 high //PTS
0xFC //PTAD 0x00 / NOTE Reading a
1 from a bit connected to a SW on the MCU means
the button is not pressed. Reading a 0 from
a bit connected to a SW on the MCU means the
button is pressed. / // Loop forever. for
() int rownum int colnum for(colnum
0 colnum lt 2 colnum) scanColumn(coln
um) rownum readRow() if(rownum !
-1) debounce() rownum
readRow() display(rownum, colnum) break
// quits outta column scan for loop //
end scanning columns // end forever // end
main // scanColumn // Parameters // int
colnum The column currently being scanned. //
Returns // void void scanColumn(int
colnum) if(colnum 0) PTAD_PTAD0
0x00 PTAD_PTAD1 0x01 PTAD_PTAD2
0x01 //PTS 0xFE else if(colnum
1) PTAD_PTAD0 0x01 PTAD_PTAD1
0x00 PTAD_PTAD2 0x01 //PTS
0xFD else if(colnum 2) PTAD_PTAD0
0x01 PTAD_PTAD1 0x01 PTAD_PTAD2
0x00 // end scanColumn function //
readRow // Parameters // none // Returns //
void int readRow() // Mask
PTAD. switch(PTAD 0x78) // No break
statements needed in these cases because we're
returning // straight outta the function from
each. case 0x70 return 0 case
0x68 return 1 case 0x58 return
2 case 0x38 return 3 default // No row
pressed. return -1 // end readRow
function // debounce // Short do-nothing for
loop to debounce switch. Increase upper //
bound of for loop if switches are not debouncing
properly. // Parameters // none //
Returns // void void debounce() int
i for(i 0 i lt 1000 i) // do nothing
loop // end debounce function // display //
Currently throws compiler warning about
"Possible loss of data". // This is due to PTT
taking in a byte while keypressed is an int, //
which is 4 bytes. EDIT Should be fixed, I hope.
Changed keypressed // to type "byte". //
This function sends data to PTT. //
Parameters // int myrow Row of the key that
is pressed. // int mycolumn Column of the key
that is pressed. // Returns // void void
display(int myrow, int mycolumn) // "-1"s are
due to the array being start-at-0 while the
keypad // row/column scan functions are
start-at-1. // Not no more. GUAH! PTT
keypressedmyrowmycolumn
Keypad interfaced to microcontroller and working,
sort of.
10
PWM
include lthidef.hgt      / common defines and
macros / include ltmc9s12c32.hgt     /
derivative information / pragma LINK_INFO
DERIVATIVE "mc9s12c32" / Written by Steven
Hawkins for Foster Phillips Dr. T. Roppel,
10/06/2006 / / Wiring notes Pinout of our
modules is at http//www.freescale.com/files/stud
ent_learning_kits/doc/user_guide/APS12C32SLKUG.pdf
(CSM-12C32 Freescale Module Data Sheet) Page
12 PT0 PWMCH0  Pin13 PT1 PWMCH1
 Pin15 PT2 PWMCH2  Pin30 PT3 PWMCH3
 Pin32 PT4 PWMCH4  Pin34 / / You can
ignore warnings about loss of data - we only care
about the bottom 8 bits   of an unsigned
integer, so any number larger than 255 will be
cut off. / // Declare function headersl int
PWMCH0Init(void) int PWMCH1Init(void) int
PWMCH2Init(void) int PWMCH3Init(void) int
PWMCH4Init(void) int PWMCH0SetFreqandDuty(unsign
ed int period,unsigned int duty) int
PWMCH1SetFreqandDuty(unsigned int period,unsigned
int duty) int PWMCH2SetFreqandDuty(unsigned int
period,unsigned int duty) int PWMCH3SetFreqandDut
y(unsigned int period,unsigned int duty) int
PWMCH4SetFreqandDuty(unsigned int period,unsigned
int duty) void doNothing(int) / Define and
initialize example array with 3 rows and 10
columns / / exampleArray01 would be 2,
examplearray11 12 / unsigned int
exampleArray310      1,2,3,4,5,6,7,8,9,1
0,      11,12,13,14,15,16,17,18,19,20,
     21,22,23,24,25,26,27,28,29,30 unsigned
int convertedDuty24 // 2 rows, 4
columns float dutyCycle24
   10.1,15.3,18.8,22.3,    28.7,35.8,43.5,57.
2       int i,j // used in FOR loops int
dummy // a dummy variable // using 30 for a
duty cycle would give you a 21/256 duty cycle
12.1                 void main(void)  / put
your own code here /  EnableInterrupts  //if
you wanted to fill in an array of percentages,
and generate the correct values for duty cycle
here's how you'd do it  for(i0ilt2i)
   for(j0jlt4j)      convertedDutyij
(int)(dutyCycleij.01256 - 1 0.5) //
0.5 is used for rounding        dummyPWMCh2In
it()    // Period of 241 microseconds 400Khz,
you really dont need to worry about frequency for
your application  // Anything above a couple
hundred hz should be fine.  // Duty cycle of
(251)/256 10.1, controls brightness  dummyPWM
Ch2SetFreqandDuty(exampleArray23,exampleArray
24)    //want a pause in your program for
some cycles?  //call a do nothing
loop.  doNothing(1000) // delays 2 clock
cycles per, so 2000 cycles here.      for()
  / wait forever /  / please make sure that
you never leave this function / int
PWMCh0Init(void) MODRR_MODRR0 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL0 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK0 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE0 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER0 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY0
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME0 1
    / PWM Channel 2 Enable / return 0 int
PWMCh1Init(void) MODRR_MODRR1 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL1 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK1 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE1 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER1 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY1
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME1 1
    / PWM Channel 2 Enable / return 0 int
PWMCh2Init(void) MODRR_MODRR2 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL2 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK2 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE2 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER2 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY2
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME2 1
    / PWM Channel 2 Enable / return 0 int
PWMCh3Init(void) MODRR_MODRR3 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL3 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK3 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE3 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER3 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY3
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME3 1
    / PWM Channel 2 Enable / return 0 int
PWMCh4Init(void) MODRR_MODRR4 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL4 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK4 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE4 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER4 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY4
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME4 1
    / PWM Channel 2 Enable / return
0 // Period is a value between 0 255.
 This value, plus 1, sets the period of the PWM
in microseconds // Frequency is 1/Period. (Ie 0
1 microsecond, 12, etc.) // Duty cycle would
be what controls brightness of an LED. It is a
value between 0 255 //   is a ratio of
 (1duty)/256. int PWMCh0SetFreqandDuty(unsigned
int period,unsigned int duty)  PWMDTY0
duty  PWMPER0 period  return 0 int
PWMCh1SetFreqandDuty(unsigned int period,unsigned
int duty)  PWMDTY1 duty  PWMPER1
period  return 0 int PWMCh2SetFreqandDuty(unsi
gned int period,unsigned int duty)  PWMDTY2
duty  PWMPER2 period  return 0 int
PWMCh3SetFreqandDuty(unsigned int period,unsigned
int duty)  PWMDTY3 duty  PWMPER3
period  return 0 int PWMCh4SetFreqandDuty(unsi
gned int period,unsigned int duty)  PWMDTY4
duty  PWMPER4 period  return 0 void
doNothing(int howmanytimes)  for(ihowmanytimesi
gt0i--)  
include lthidef.hgt      / common defines and
macros / include ltmc9s12c32.hgt     /
derivative information / pragma LINK_INFO
DERIVATIVE "mc9s12c32" / Written by Steven
Hawkins for Foster Phillips Dr. T. Roppel,
10/06/2006 / / Wiring notes Pinout of our
modules is at http//www.freescale.com/files/stud
ent_learning_kits/doc/user_guide/APS12C32SLKUG.pdf
(CSM-12C32 Freescale Module Data Sheet) Page
12 PT0 PWMCH0  Pin13 PT1 PWMCH1
 Pin15 PT2 PWMCH2  Pin30 PT3 PWMCH3
 Pin32 PT4 PWMCH4  Pin34 / / You can
ignore warnings about loss of data - we only care
about the bottom 8 bits   of an unsigned
integer, so any number larger than 255 will be
cut off. / // Declare function headersl int
PWMCH0Init(void) int PWMCH1Init(void) int
PWMCH2Init(void) int PWMCH3Init(void) int
PWMCH4Init(void) int PWMCH0SetFreqandDuty(unsign
ed int period,unsigned int duty) int
PWMCH1SetFreqandDuty(unsigned int period,unsigned
int duty) int PWMCH2SetFreqandDuty(unsigned int
period,unsigned int duty) int PWMCH3SetFreqandDut
y(unsigned int period,unsigned int duty) int
PWMCH4SetFreqandDuty(unsigned int period,unsigned
int duty) void doNothing(int) / Define and
initialize example array with 3 rows and 10
columns / / exampleArray01 would be 2,
examplearray11 12 / unsigned int
exampleArray310      1,2,3,4,5,6,7,8,9,1
0,      11,12,13,14,15,16,17,18,19,20,
     21,22,23,24,25,26,27,28,29,30 unsigned
int convertedDuty24 // 2 rows, 4
columns float dutyCycle24
   10.1,15.3,18.8,22.3,    28.7,35.8,43.5,57.
2       int i,j // used in FOR loops int
dummy // a dummy variable // using 30 for a
duty cycle would give you a 21/256 duty cycle
12.1                 void main(void)  / put
your own code here /  EnableInterrupts  //if
you wanted to fill in an array of percentages,
and generate the correct values for duty cycle
here's how you'd do it  for(i0ilt2i)
   for(j0jlt4j)      convertedDutyij
(int)(dutyCycleij.01256 - 1 0.5) //
0.5 is used for rounding        dummyPWMCh2In
it()    // Period of 241 microseconds 400Khz,
you really dont need to worry about frequency for
your application  // Anything above a couple
hundred hz should be fine.  // Duty cycle of
(251)/256 10.1, controls brightness  dummyPWM
Ch2SetFreqandDuty(exampleArray23,exampleArray
24)    //want a pause in your program for
some cycles?  //call a do nothing
loop.  doNothing(1000) // delays 2 clock
cycles per, so 2000 cycles here.      for()
  / wait forever /  / please make sure that
you never leave this function / int
PWMCh0Init(void) MODRR_MODRR0 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL0 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK0 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE0 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER0 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY0
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME0 1
    / PWM Channel 2 Enable / return 0 int
PWMCh1Init(void) MODRR_MODRR1 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL1 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK1 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE1 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER1 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY1
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME1 1
    / PWM Channel 2 Enable / return 0 int
PWMCh2Init(void) MODRR_MODRR2 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL2 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK2 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE2 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER2 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY2
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME2 1
    / PWM Channel 2 Enable / return 0 int
PWMCh3Init(void) MODRR_MODRR3 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL3 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK3 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE3 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER3 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY3
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME3 1
    / PWM Channel 2 Enable / return 0 int
PWMCh4Init(void) MODRR_MODRR4 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL4 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK4 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE4 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER4 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY4
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME4 1
    / PWM Channel 2 Enable / return
0 // Period is a value between 0 255.
 This value, plus 1, sets the period of the PWM
in microseconds // Frequency is 1/Period. (Ie 0
1 microsecond, 12, etc.) // Duty cycle would
be what controls brightness of an LED. It is a
value between 0 255 //   is a ratio of
 (1duty)/256. int PWMCh0SetFreqandDuty(unsigned
int period,unsigned int duty)  PWMDTY0
duty  PWMPER0 period  return 0 int
PWMCh1SetFreqandDuty(unsigned int period,unsigned
int duty)  PWMDTY1 duty  PWMPER1
period  return 0 int PWMCh2SetFreqandDuty(unsi
gned int period,unsigned int duty)  PWMDTY2
duty  PWMPER2 period  return 0 int
PWMCh3SetFreqandDuty(unsigned int period,unsigned
int duty)  PWMDTY3 duty  PWMPER3
period  return 0 int PWMCh4SetFreqandDuty(unsi
gned int period,unsigned int duty)  PWMDTY4
duty  PWMPER4 period  return 0 void
doNothing(int howmanytimes)  for(ihowmanytimesi
gt0i--)  
include lthidef.hgt      / common defines and
macros / include ltmc9s12c32.hgt     /
derivative information / pragma LINK_INFO
DERIVATIVE "mc9s12c32" / Written by Steven
Hawkins for Foster Phillips Dr. T. Roppel,
10/06/2006 / / Wiring notes Pinout of our
modules is at http//www.freescale.com/files/stud
ent_learning_kits/doc/user_guide/APS12C32SLKUG.pdf
(CSM-12C32 Freescale Module Data Sheet) Page
12 PT0 PWMCH0  Pin13 PT1 PWMCH1
 Pin15 PT2 PWMCH2  Pin30 PT3 PWMCH3
 Pin32 PT4 PWMCH4  Pin34 / / You can
ignore warnings about loss of data - we only care
about the bottom 8 bits   of an unsigned
integer, so any number larger than 255 will be
cut off. / // Declare function headersl int
PWMCH0Init(void) int PWMCH1Init(void) int
PWMCH2Init(void) int PWMCH3Init(void) int
PWMCH4Init(void) int PWMCH0SetFreqandDuty(unsign
ed int period,unsigned int duty) int
PWMCH1SetFreqandDuty(unsigned int period,unsigned
int duty) int PWMCH2SetFreqandDuty(unsigned int
period,unsigned int duty) int PWMCH3SetFreqandDut
y(unsigned int period,unsigned int duty) int
PWMCH4SetFreqandDuty(unsigned int period,unsigned
int duty) void doNothing(int) / Define and
initialize example array with 3 rows and 10
columns / / exampleArray01 would be 2,
examplearray11 12 / unsigned int
exampleArray310      1,2,3,4,5,6,7,8,9,1
0,      11,12,13,14,15,16,17,18,19,20,
     21,22,23,24,25,26,27,28,29,30 unsigned
int convertedDuty24 // 2 rows, 4
columns float dutyCycle24
   10.1,15.3,18.8,22.3,    28.7,35.8,43.5,57.
2       int i,j // used in FOR loops int
dummy // a dummy variable // using 30 for a
duty cycle would give you a 21/256 duty cycle
12.1                 void main(void)  / put
your own code here /  EnableInterrupts  //if
you wanted to fill in an array of percentages,
and generate the correct values for duty cycle
here's how you'd do it  for(i0ilt2i)
   for(j0jlt4j)      convertedDutyij
(int)(dutyCycleij.01256 - 1 0.5) //
0.5 is used for rounding        dummyPWMCh2In
it()    // Period of 241 microseconds 400Khz,
you really dont need to worry about frequency for
your application  // Anything above a couple
hundred hz should be fine.  // Duty cycle of
(251)/256 10.1, controls brightness  dummyPWM
Ch2SetFreqandDuty(exampleArray23,exampleArray
24)    //want a pause in your program for
some cycles?  //call a do nothing
loop.  doNothing(1000) // delays 2 clock
cycles per, so 2000 cycles here.      for()
  / wait forever /  / please make sure that
you never leave this function / int
PWMCh0Init(void) MODRR_MODRR0 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL0 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK0 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE0 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER0 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY0
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME0 1
    / PWM Channel 2 Enable / return 0 int
PWMCh1Init(void) MODRR_MODRR1 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL1 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK1 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE1 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER1 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY1
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME1 1
    / PWM Channel 2 Enable / return 0 int
PWMCh2Init(void) MODRR_MODRR2 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL2 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK2 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE2 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER2 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY2
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME2 1
    / PWM Channel 2 Enable / return 0 int
PWMCh3Init(void) MODRR_MODRR3 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL3 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK3 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE3 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER3 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY3
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME3 1
    / PWM Channel 2 Enable / return 0 int
PWMCh4Init(void) MODRR_MODRR4 1   / Connect
the PWM Module to PT2/                           
        // the above line is the one I'm having
the hardest time understanding PWMPOL_PPOL4 1
  / PWM Channel 2 Polarity / PWMCLK_PCLK4 0
  / PWM Channel 2 Source Clock B / PWMPRCLK
0x30    / Clock B Prescaler Bus Clock/8 1
MHz / PWMCAE_CAE4 0    / PWM Channel 2 left
aligned /   PWMCTL 0x00      / PWM Control
Register / PWMPER4 0xFF         / PWM
Channel 2 Period 256us (Freq 3.9KHz)
/                         / (FF)base16
(11111111)base2 (255)base10 /                 
        / 1/Period Frequency / PWMDTY4
0x7F     / PWM Channel 2 Duty Cycle 50
(01111111)base2 (127)base10/ PWME_PWME4 1
    / PWM Channel 2 Enable / return
0 // Period is a value between 0 255.
 This value, plus 1, sets the period of the PWM
in microseconds // Frequency is 1/Period. (Ie 0
1 microsecond, 12, etc.) // Duty cycle would
be what controls brightness of an LED. It is a
value between 0 255 //   is a ratio of
 (1duty)/256. int PWMCh0SetFreqandDuty(unsigned
int period,unsigned int duty)  PWMDTY0
duty  PWMPER0 period  return 0 int
PWMCh1SetFreqandDuty(unsigned int period,unsigned
int duty)  PWMDTY1 duty  PWMPER1
period  return 0 int PWMCh2SetFreqandDuty(unsi
gned int period,unsigned int duty)  PWMDTY2
duty  PWMPER2 period  return 0 int
PWMCh3SetFreqandDuty(unsigned int period,unsigned
int duty)  PWMDTY3 duty  PWMPER3
period  return 0 int PWMCh4SetFreqandDuty(unsi
gned int period,unsigned int duty)  PWMDTY4
duty  PWMPER4 period  return 0 void
doNothing(int howmanytimes)  for(ihowmanytimesi
gt0i--)  
PWM control for buzzer written and debugged
11
Software
  • Continued progress on database and interface
    programming.
  • Solved problem with java interface MySQL
    (database environment and language) interaction

12
Interface
// JanusDB // Created 2006/09/29 // Common
database functions for the java part of
Janus. import java.util. import
java.sql. public class JanusDB static
String url "jdbcmysql//localhost/JanusDoors"
static String user "janus" static String
pass "j0a9n1u5s" static String dbname
"JanusDoors" Connection conn
null Statement stmt null ResultSet rst
null // Constructor public
JanusDB() try Class.forName("com.mysql
.jdbc.Driver") catch (Exception
e) System.err.println("Error constructing
JanusDB object.\n") System.err.println(e)
// Connect to the JanusDoors db. public
void connect() throws SQLException conn
DriverManager.getConnection(url, user,
pass) stmt conn.createStatement() //
Disconnect from the JanusDoors db. public void
disconnect() throws SQLException if (rst !
null) rst.close() if (stmt ! null)
stmt.close() if (conn ! null)
conn.close() // Execute query, and return
the results. public ResultSet query(String
query) throws SQLException return
stmt.executeQuery(query) // Update
database with query. public void update(String
query) throws SQLException stmt.executeUpdate
(query) // Figures out if the user is
valid. public boolean validateUser(int keycode,
int roomID) throws SQLException boolean
userIsValid false String sqlquery "SELECT
id FROM users WHERE keycode'" keycode
"'" rst query(sqlquery) // Check
results to find if it returns a user. // if rst
returns only one row, you're good? String
userID "" String building "" String
roomNum "" if (rst.next()) userID
rst.getString("id") sqlquery "SELECT
building,number FROM rooms WHERE id'" roomID
"'" rst query(sqlquery) if
(rst.next()) building rst.getString("buil
ding") roomNum rst.getString("number")
System.out.println(userID " "
building " " roomNum) sqlquery
"SELECT building, room_number FROM room_users
WHERE user_id'" userID "'" rst
query(sqlquery) while (rst.next()) //
if user is allowed into this room... System.out
.print(rst.getString("building") " "
rst.getString("room_number")) if
((rst.getString("building") building)
(rst.getString("room_number")
roomNum)) userIsValid
true System.out.println("User is
Valid? " (userIsValid ? "Yes."
"No.")) return userIsValid // Logs
the action to the db. private void log(String
user, String room, String action) throws
SQLException
// JanusDB // Created 2006/09/29 // Common
database functions for the java part of
Janus. import java.util. import
java.sql. public class JanusDB static
String url "jdbcmysql//localhost/JanusDoors"
static String user "janus" static String
pass "j0a9n1u5s" static String dbname
"JanusDoors" Connection conn
null Statement stmt null ResultSet rst
null // Constructor public
JanusDB() try Class.forName("com.mysql
.jdbc.Driver") catch (Exception
e) System.err.println("Error constructing
JanusDB object.\n") System.err.println(e)
// Connect to the JanusDoors db. public
void connect() throws SQLException conn
DriverManager.getConnection(url, user,
pass) stmt conn.createStatement() //
Disconnect from the JanusDoors db. public void
disconnect() throws SQLException if (rst !
null) rst.close() if (stmt ! null)
stmt.close() if (conn ! null)
conn.close() // Execute query, and return
the results. public ResultSet query(String
query) throws SQLException return
stmt.executeQuery(query) // Update
database with query. public void update(String
query) throws SQLException stmt.executeUpdate
(query) // Figures out if the user is
valid. public boolean validateUser(int keycode,
int roomID) throws SQLException boolean
userIsValid false String sqlquery "SELECT
id FROM users WHERE keycode'" keycode
"'" rst query(sqlquery) // Check
results to find if it returns a user. // if rst
returns only one row, you're good? String
userID "" String building "" String
roomNum "" if (rst.next()) userID
rst.getString("id") sqlquery "SELECT
building,number FROM rooms WHERE id'" roomID
"'" rst query(sqlquery) if
(rst.next()) building rst.getString("buil
ding") roomNum rst.getString("number")
System.out.println(userID " "
building " " roomNum) sqlquery
"SELECT building, room_number FROM room_users
WHERE user_id'" userID "'" rst
query(sqlquery) while (rst.next()) //
if user is allowed into this room... System.out
.print(rst.getString("building") " "
rst.getString("room_number")) if
((rst.getString("building") building)
(rst.getString("room_number")
roomNum)) userIsValid
true System.out.println("User is
Valid? " (userIsValid ? "Yes."
"No.")) return userIsValid // Logs
the action to the db. private void log(String
user, String room, String action) throws
SQLException
// JanusDB // Created 2006/09/29 // Common
database functions for the java part of
Janus. import java.util. import
java.sql. public class JanusDB static
String url "jdbcmysql//localhost/JanusDoors"
static String user "janus" static String
pass "j0a9n1u5s" static String dbname
"JanusDoors" Connection conn
null Statement stmt null ResultSet rst
null // Constructor public
JanusDB() try Class.forName("com.mysql
.jdbc.Driver") catch (Exception
e) System.err.println("Error constructing
JanusDB object.\n") System.err.println(e)
// Connect to the JanusDoors db. public
void connect() throws SQLException conn
DriverManager.getConnection(url, user,
pass) stmt conn.createStatement() //
Disconnect from the JanusDoors db. public void
disconnect() throws SQLException if (rst !
null) rst.close() if (stmt ! null)
stmt.close() if (conn ! null)
conn.close() // Execute query, and return
the results. public ResultSet query(String
query) throws SQLException return
stmt.executeQuery(query) // Update
database with query. public void update(String
query) throws SQLException stmt.executeUpdate
(query) // Figures out if the user is
valid. public boolean validateUser(int keycode,
int roomID) throws SQLException boolean
userIsValid false String sqlquery "SELECT
id FROM users WHERE keycode'" keycode
"'" rst query(sqlquery) // Check
results to find if it returns a user. // if rst
returns only one row, you're good? String
userID "" String building "" String
roomNum "" if (rst.next()) userID
rst.getString("id") sqlquery "SELECT
building,number FROM rooms WHERE id'" roomID
"'" rst query(sqlquery) if
(rst.next()) building rst.getString("buil
ding") roomNum rst.getString("number")
System.out.println(userID " "
building " " roomNum) sqlquery
"SELECT building, room_number FROM room_users
WHERE user_id'" userID "'" rst
query(sqlquery) while (rst.next()) //
if user is allowed into this room... System.out
.print(rst.getString("building") " "
rst.getString("room_number")) if
((rst.getString("building") building)
(rst.getString("room_number")
roomNum)) userIsValid
true System.out.println("User is
Valid? " (userIsValid ? "Yes."
"No.")) return userIsValid // Logs
the action to the db. private void log(String
user, String room, String action) throws
SQLException
Continued steady progress on database interface
13
Goals for next week
  • Serial Port monitor of internal microcontroler
    state
  • Code working without debugger connected
  • Display message from microcontroller on display
  • Microcontrollers communicating across CAN
    (controlled area network)
  • Microcontrollers querying database
    microcontroller
  • Database configured
  • Continued Documentation

14
Timeline Again
15
Conclusion
  • Slipped on working LCD
  • Had a working keypad and code but we broke it
  • Need to start programming to flash instead of RAM
  • Need to start working on CAN

16
Questions
?
Write a Comment
User Comments (0)
About PowerShow.com