The Smart Card Detective (SCD)
Defines | Functions
scd_io.h File Reference

scd_io.h header file More...

#include <stdio.h>
#include <avr/io.h>

Go to the source code of this file.

Defines

#define LCD_COMMAND_DELAY   40
 Delay of LCD commands.
#define BUTTON_A   0x01
 value for Button A in result from GetButton function
#define BUTTON_B   0x02
 value for Button B in result from GetButton function
#define BUTTON_C   0x04
 value for Button C in result from GetButton function
#define BUTTON_D   0x08
 value for Button D in result from GetButton function

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.
void T_C4On ()
void T_C8On ()
void T_C4Off ()
void T_C8Off ()
void JTAG_P1_High ()
void JTAG_P3_High ()
void JTAG_P1_Low ()
void JTAG_P3_Low ()
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 GetLCDState ()
 Return the state (on/off) of the LCD.
void SetLCDState (uint8_t state)
 Set the state of the LCD.
void InitLCD ()
 Initialize LCD.
void WriteStringLCD (char *string, uint8_t len)
 Display a string on LCD.
int LcdPutchar (char c, FILE *unused)
 Send character to the LCD display.
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.
uint16_t Read16bitRegister (volatile uint16_t *reg)
 Read multiple bytes from EEPROM.
void InitUSART (uint16_t baudUBRR)
 Initialise USART.
void DisableUSART ()
 Disable USART.
void SendCharUSART (char data)
char GetCharUSART (void)
void FlushUSART (void)
char * GetLineUSART ()
void SendLineUSART (const char *data)

Detailed Description

scd_io.h header file

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

Copyright (C) 2012 Omar Choudary (omar.choudary@cl.cam.ac.uk)

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file scd_io.h.


Define Documentation

#define BUTTON_A   0x01

value for Button A in result from GetButton function

Definition at line 44 of file scd_io.h.

#define BUTTON_B   0x02

value for Button B in result from GetButton function

Definition at line 47 of file scd_io.h.

#define BUTTON_C   0x04

value for Button C in result from GetButton function

Definition at line 50 of file scd_io.h.

#define BUTTON_D   0x08

value for Button D in result from GetButton function

Definition at line 53 of file scd_io.h.

#define LCD_COMMAND_DELAY   40

Delay of LCD commands.

Definition at line 41 of file scd_io.h.


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 465 of file scd_io.c.

void DisableUSART ( )

Disable USART.

Definition at line 646 of file scd_io.c.

void FlushUSART ( void  )

Flush the receive buffer, useful in case of errors.

Definition at line 684 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 230 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 179 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 190 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 202 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 214 of file scd_io.c.

char GetCharUSART ( void  )

Get a character from the USART. Method from the datasheet.

Definition at line 672 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 273 of file scd_io.c.

char* GetLineUSART ( )

This method receives a line (ended CR LF) from the USART

Returns:
the line contents, removing the trailing CR LF and appending the NUL ('\0') character. The caller is responsible for eliberating the memory occupied by the returned string.

Definition at line 697 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 427 of file scd_io.c.

void InitUSART ( uint16_t  baudUBRR)

Initialise USART.

Initiualise the USART port

Parameters:
baudUBRRthe baud UBRR parameter as given in table 18-12 of the datasheet, page 203. The formula is: baud = FCLK / (16 * (baudUBRR + 1)). So for FCLK = 16 MHz and desired BAUD = 9600 bps => baudUBRR = 103.

Definition at line 629 of file scd_io.c.

void JTAG_P1_High ( )

Definition at line 146 of file scd_io.c.

void JTAG_P1_Low ( )

Definition at line 152 of file scd_io.c.

void JTAG_P3_High ( )

Definition at line 158 of file scd_io.c.

void JTAG_P3_Low ( )

Definition at line 164 of file scd_io.c.

void LCDOff ( )

Switch LCD off.

This function turns off the LCD display

Definition at line 487 of file scd_io.c.

void LCDOn ( )

Switch LCD on.

This function turns on the LCD display

Definition at line 498 of file scd_io.c.

int LcdPutchar ( char  c,
FILE *  unused 
)

Send character to the LCD display.

Definition at line 391 of file scd_io.c.

void Led1Off ( )

Turn off Led1.

Definition at line 84 of file scd_io.c.

void Led1On ( )

Turn on Led1.

Definition at line 60 of file scd_io.c.

void Led2Off ( )

Turn off Led2.

Definition at line 93 of file scd_io.c.

void Led2On ( )

Turn on Led2.

Definition at line 66 of file scd_io.c.

void Led3Off ( )

Turn off Led3.

Definition at line 102 of file scd_io.c.

void Led3On ( )

Turn on Led3.

Definition at line 72 of file scd_io.c.

void Led4Off ( )

Turn off Led4.

Definition at line 111 of file scd_io.c.

void Led4On ( )

Turn on Led4.

Definition at line 78 of file scd_io.c.

uint16_t Read16bitRegister ( volatile uint16_t *  reg)

Read multiple bytes from EEPROM.

Definition at line 52 of file utils.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:
addraddress of first byte to be read
lennumber 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 601 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:
addraddress of byte to be read
Returns:
data byte read
See also:
ReadBytesEEPROM

Definition at line 549 of file scd_io.c.

void SendCharUSART ( char  data)

Transmit a character throught the USART. Method as in the datasheet.

Parameters:
datathe character to be sent

Definition at line 659 of file scd_io.c.

void SendLineUSART ( const char *  data)

This method sends a data string (without adding CR LF) to the USART

Parameters:
datathe string to be transmitted, ended with the NUL ('\0') character.

Definition at line 733 of file scd_io.c.

void SetLCDState ( uint8_t  state)

Set the state of the LCD.

Definition at line 282 of file scd_io.c.

void T_C4Off ( )

Definition at line 134 of file scd_io.c.

void T_C4On ( )

Definition at line 122 of file scd_io.c.

void T_C8Off ( )

Definition at line 140 of file scd_io.c.

void T_C8On ( )

Definition at line 128 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:
addraddress of first byte to be written
databytes to be written
lennumber of bytes to be written
See also:
WriteSingleByteEEPROM

Definition at line 571 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:
addraddress of byte to be written
databyte to be written
See also:
WriteBytesEEPROM

Definition at line 523 of file scd_io.c.

void WriteStringLCD ( char *  string,
uint8_t  len 
)

Display a string on LCD.

Write a string to the LCD

Parameters:
stringstring to be written
lenlength of the string

Definition at line 348 of file scd_io.c.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines