Docsity

Programming Assignment 2: Push Button Light and Counting for CSE 30, Fall 2009, Assignments of Political Science

Toggle sidebar
bg1
CSE 30 FALL 2009
1
Programming Assignment 2: Push Button Light and Counting
Associated C ypress Boa rd: CY3214
Associated Part F ami ly : CY8C24894-24LFXI
PSoC D esigner V ersion: 5.0
Due: 2pm October 15, 2009
Summa r y
You will create a system that does the following:
LED1 is ON when only S1 is pressed
LED2 is ON when only S2 is pressed
LED3 is ON when both S1 and S2 are pressed together
No LED is ON when nothing is pressed
Have the LCD display “Button Counter” on the first line.
Have “S1 = N” and “S2 = M” on the second line where N and M
are the amount of times S1 and S2 were pressed respectively.
Setu p
Open PSoC Designer and click on
Fil e
->
New Proj e ct.
Select
Chip-level Projec t
and Type PA2
in the
Na
m
e
box. Click
Browse
to select the directory where you are storing your Lab
assignments and click the check box to create directory for workspace. Click
OK
.
In the next window, select part CY8C24894-24LXI through the View%Catalog… button and
choose to Generate Main file using C. Click
Finish
when done.
pf3
pf4
pf5

Partial preview of the text

Download Programming Assignment 2: Push Button Light and Counting for CSE 30, Fall 2009 and more Assignments Political Science in PDF only on Docsity!

Programming Assignment 2: Push Button Light and Counting

Associated C ypress Board: CY Associated Pa rt Family: CY8C24894-24LFXI PSoC Designer V ersion: 5. Due: 2pm October 15, 2009

Summary

You will create a system that does the following:

LED1 is ON when only S1 is pressed LED2 is ON when only S2 is pressed LED3 is ON when both S1 and S2 are pressed together No LED is ON when nothing is pressed

Have the LCD display “Button Counter” on the first line. Have “S1 = N” and “S2 = M” on the second line where N and M are the amount of times S1 and S2 were pressed respectively.

Setup

Open PSoC Designer and click on File -> New Project. Select Chip-level Project and Type PA

in the Nam e box. Click Browse to select the directory where you are storing your Lab

assignments and click the check box to create directory for workspace. Click O K.

In the next window, select part CY8C24894-24LXI through the View Catalog… button and

choose to Generate Main file using C. Click Finish when done.

A dding User M odules Now add the user modules that are necessary to implement this project (an LCD, and 3 LEDs).

Click on View -> User Module Catalog. First add the LCD. In the User Module Catalog,

expand Misc Digital, Right Click on LC D and select Place.

You should see the LCD module show up in the Workspace Explorer Screen on the right.

Now add three LEDs. In the User Module Catalog, expand Misc Digital, Right Click on LE D

and select Place. Repeat another two times so a total of three LEDs are added. Now you should

see all 4 user modules added in the Workspace Explorer:

other parameters for this pin. Name this pin ‘ PB2’ (to mean PushButton2) and change the Drive

of this pin to ‘ PullDown’ as shown in the figure below. PullDown just means that the button will

have a ‘0 value when not pressed and a ‘1’ value when pressed. Click ‘OK’ in the window to make the changes. Repeat for PB1 on Port_3_5.

A dding Software Now that you have the hardware hooked up, you can write a software program to tell the microcontroller what to do. In the Workspace Explorer, Expand the Folder and Source Files Tab

and double click on Main.c.

Before you write any code, generate the configuration files you will need for the project. Select

Build-> Gener ate Configuration Files for ‘<project_name>’ Project.

You will now see an additional lib folder under the project folder in the Windows Explorer.

These library files contain the code necessary to ‘talk’ to the user modules you have added.

Take a look at some of the Library header files to see what kind of function calls you can make to the user modules. For example, open up LED_1.h and notice you have the following function calls available for ‘talking’ to LED1:

extern void LED_1_Start(void); extern void LED_1_Stop(void); extern void LED_1_On(void); extern void LED_1_Off(void); extern void LED_1_Switch(BYTE bSwitch); extern void LED_1_Invert(void); extern BYTE LED_1_GetState(void);

You also might be interested in looking at the function definitions listed under “Library Source Files.” You will notice these are all written in an assembly language used for Cypress microcontrollers.

Now you are ready to write some code. Achieve the same functionality as the summary discussed at the top of this lab. Some help is given on the following page.

User M odule I nitialization You will need to initialize your user modules. That is, when your program starts up (or when you hit reset), what should your LEDs and LCD be doing? You should set the LEDs to be OFF and the LCD to display a message that each button has zero counts.

W iring the Boar d Your board is almost ready to work – you just need to wire it up according to how you specified your port mapping in the beginning of this lab. Wire LED1 to P30, LED2 to P31, LED3 to P32, S1 to P35, and S2 to P37. Be careful not to hook the push buttons to GND as this could potentially damage the board.

Now go to the Programmer, hit, Toggle Power and have fun pushing buttons and blinking lights!

Congratulations! You’re done!