scd_io.c File Reference

scd_io.c source file More...

#include <avr/io.h>
#include <string.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <avr/eeprom.h>
#include "scd_io.h"

Go to the source code of this file.

Defines

#define F_CPU   16000000UL
 Frequency of CPU, used for _delay_XX functions.

Functions

void Led1On ()
 Turn on Led1.
void Led2On ()
 Turn on Led2.
void Led3On ()
 Turn on Led3.
void Led4On ()
 Turn on Led4.
void Led1Off ()
 Turn off Led1.
void Led2Off ()
 Turn off Led2.
void Led3Off ()
 Turn off Led3.
void Led4Off ()
 Turn off Led4.
uint8_t GetButtonA ()
 Get status of button A.
uint8_t GetButtonB ()
 Get status of button B.
uint8_t GetButtonC ()
 Get status of button C.
uint8_t GetButtonD ()
 Get status of button D.
uint8_t GetButton ()
 Returs a 1-hot encoded list of buttons pressed.
uint8_t GetLCDStatus ()
uint8_t GetLCDState ()
 Return the state (on/off) of the LCD.
void SetLCDState (uint8_t state)
 Set the state of the LCD.
uint8_t SendLCDCommand (uint8_t RS, uint8_t RW, uint8_t data, uint16_t delay_us)
void FillScreen ()
void WriteStringLCD (char *string, uint8_t len)
 Display a string on LCD.
uint8_t LcdPutchar (uint8_t c, FILE *unused)
 Send character to the LCD display.
void InitLCD ()
 Initialize LCD.
uint8_t CheckLCD ()
 Check if the LCD is working properly.
void LCDOff ()
 Switch LCD off.
void LCDOn ()
 Switch LCD on.
void WriteSingleByteEEPROM (uint16_t addr, uint8_t data)
 Write a single byte to EEPROM.
uint8_t ReadSingleByteEEPROM (uint16_t addr)
 Read a single byte from EEPROM.
void WriteBytesEEPROM (uint16_t addr, uint8_t *data, uint16_t len)
 Write multiple bytes to EEPROM.
uint8_t * ReadBytesEEPROM (uint16_t addr, uint16_t len)
 Read multiple bytes from EEPROM.
void EraseEEPROM ()
 Clears the contents of the EEPROM.

Detailed Description

scd_io.c source file

This file implement the functions for all micro-controller I/O functions, including control of LCD, leds and buttons

Copyright (C) 2010 Omar Choudary (osc22@cam.ac.uk)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Definition in file scd_io.c.


Define Documentation

#define F_CPU   16000000UL

Frequency of CPU, used for _delay_XX functions.

Definition at line 26 of file scd_io.c.


Function Documentation

uint8_t CheckLCD (  ) 

Check if the LCD is working properly.

This function checks if the LCD is working properly

Returns:
0 if LCD works fine, non-zero if there is a problem

Definition at line 407 of file scd_io.c.

void EraseEEPROM (  ) 

Clears the contents of the EEPROM.

This function erases the entire contents of the EEPROM. This method stops interrupts while clearing the EEPROM.

Definition at line 567 of file scd_io.c.

void FillScreen (  ) 

Definition at line 265 of file scd_io.c.

uint8_t GetButton (  ) 

Returs a 1-hot encoded list of buttons pressed.

This function checks all the buttons for being pressed and returns a 1-hot encoded byte representing each pressed button.

Returns:
1-hot encoded byte representing the buttons that are pressed (1 = pressed, 0 = not pressed). If there is no button pressed the function returns 0. The define directives (BUTTON_A, BUTTON_B, etc.) provide the correspondence between each bit of the result and the button it refers to. *

Definition at line 172 of file scd_io.c.

uint8_t GetButtonA (  ) 

Get status of button A.

Get the status of button A

Returns:
0 if button is pressed, non-zero otherwise

Definition at line 121 of file scd_io.c.

uint8_t GetButtonB (  ) 

Get status of button B.

Get the status of button B

Returns:
0 if button is pressed, non-zero otherwise

Definition at line 132 of file scd_io.c.

uint8_t GetButtonC (  ) 

Get status of button C.

Get the status of button C

Returns:
0 if button is pressed, non-zero otherwise

Definition at line 144 of file scd_io.c.

uint8_t GetButtonD (  ) 

Get status of button D.

Get the status of button D

Returns:
0 if button is pressed, non-zero otherwise

Definition at line 156 of file scd_io.c.

uint8_t GetLCDState (  ) 

Return the state (on/off) of the LCD.

Return the state (on/off) of the LCD

Definition at line 215 of file scd_io.c.

uint8_t GetLCDStatus (  ) 

Definition at line 195 of file scd_io.c.

void InitLCD (  ) 

Initialize LCD.

This function is used to initialize the LCD. It should be called before any other operation on the LCD.

Definition at line 369 of file scd_io.c.

void LCDOff (  ) 

Switch LCD off.

This function turns off the LCD display

Definition at line 429 of file scd_io.c.

void LCDOn (  ) 

Switch LCD on.

This function turns on the LCD display

Definition at line 440 of file scd_io.c.

uint8_t LcdPutchar ( uint8_t  c,
FILE *  unused 
)

Send character to the LCD display.

Definition at line 333 of file scd_io.c.

void Led1Off (  ) 

Turn off Led1.

Definition at line 75 of file scd_io.c.

void Led1On (  ) 

Turn on Led1.

Definition at line 51 of file scd_io.c.

void Led2Off (  ) 

Turn off Led2.

Definition at line 84 of file scd_io.c.

void Led2On (  ) 

Turn on Led2.

Definition at line 57 of file scd_io.c.

void Led3Off (  ) 

Turn off Led3.

Definition at line 93 of file scd_io.c.

void Led3On (  ) 

Turn on Led3.

Definition at line 63 of file scd_io.c.

void Led4Off (  ) 

Turn off Led4.

Definition at line 102 of file scd_io.c.

void Led4On (  ) 

Turn on Led4.

Definition at line 69 of file scd_io.c.

uint8_t* ReadBytesEEPROM ( uint16_t  addr,
uint16_t  len 
)

Read multiple bytes from EEPROM.

This function reads multiple bytes from the EEPROM. This method stops interrupts while reading the bytes.

Parameters:
addr address of first byte to be read
len number of bytes to be read
Returns:
the bytes read from the EEPROM. This method allocates the necessary memory to store the bytes. The caller is responsible for eliberating this memory after use. If this method is unsuccessful it will return NULL.
See also:
ReadSingleByteEEPROM

Definition at line 543 of file scd_io.c.

uint8_t ReadSingleByteEEPROM ( uint16_t  addr  ) 

Read a single byte from EEPROM.

This function reads a sigle byte from the EEPROM. Its code is mainly taken from the datasheet. This method does not change the interrupt vector so it should be handled with care. It is better to use ReadBytesEEPROM as it takes care of interrupts and reads multiple bytes at once.

Parameters:
addr address of byte to be read
Returns:
data byte read
See also:
ReadBytesEEPROM

Definition at line 491 of file scd_io.c.

uint8_t SendLCDCommand ( uint8_t  RS,
uint8_t  RW,
uint8_t  data,
uint16_t  delay_us 
)

Definition at line 231 of file scd_io.c.

void SetLCDState ( uint8_t  state  ) 

Set the state of the LCD.

Definition at line 224 of file scd_io.c.

void WriteBytesEEPROM ( uint16_t  addr,
uint8_t *  data,
uint16_t  len 
)

Write multiple bytes to EEPROM.

This function writes multiple bytes to the EEPROM. This method stops interrupts while writing the bytes.

Parameters:
addr address of first byte to be written
data bytes to be written
len number of bytes to be written
See also:
WriteSingleByteEEPROM

Definition at line 513 of file scd_io.c.

void WriteSingleByteEEPROM ( uint16_t  addr,
uint8_t  data 
)

Write a single byte to EEPROM.

This function writes a sigle byte to the EEPROM. Its code is mainly taken from the datasheet. This method does not change the interrupt vector so it should be handled with care. It is better to use WriteBytesEEPROM as it takes care of interrupts and writes multiple bytes at once.

Parameters:
addr address of byte to be written
data byte to be written
See also:
WriteBytesEEPROM

Definition at line 465 of file scd_io.c.

void WriteStringLCD ( char *  string,
uint8_t  len 
)

Display a string on LCD.

Write a string to the LCD

Parameters:
string string to be written
len length of the string

Definition at line 290 of file scd_io.c.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
Generated on Wed Mar 16 14:48:51 2011 for The Smart Card Detective (SCD) by  doxygen 1.6.3