Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro...

24

Click here to load reader

Transcript of Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro...

Page 1: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

ECE 477

C|R|U

Pranav KabraBrandon FaneMohnish RathiSumit Mehra

Homework #10

Due: 11/11/04

Page 2: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u

Introduction The Cru is a wireless digital audio receiver. It enables the user to play music stored conveniently on

their computer through their home stereo with no wiring between the computer and the stereo necessary. The

user can queue up their music via a web page from any computer on the network and listen to it in the desired

order in whichever room they see fit. The songs will be stored on a USB flash drive and kept there until they

are played through the Cru. The only wiring required will be an audio cable between the Cru and the user’s

stereo as well as a power connection. Song order and other functionality such as skipping and fast forward will

be available on the device via an appropriately labeled keypad. The Cru is a digital wireless bridge between a

PC and a home stereo system.

All the software used needs to be embedded since we wish for the CRU to be a standalone device with

no computer interfacing needed. All our software is written for and placed in the Rabbit 3000 micro controller

and hence we decided to use Dynamic C 9, a variation of C written specifically for Rabbit micro controllers in

embedded systems. All other peripherals interact with our central micro controller via on-chip software.

2

Page 3: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u

Software Design Considerations

The software design for the c|r|u was completely done using Dynamic C. During the first half of the

semester, we used the Dynamic C 8.61 installed on the lab computers to progress on our software design. Later

we migrated over to version 9.10 when we choose to use the on-board xD Card on the RCM 3360 core module

in our design. The choice of Dynamic C was bound to the fact that we choose a Rabbit 3000 as the embedded

microprocessor for our design. The ease of programming Dynamic C, which is quite similar to common C

syntax made software design quite simple helping us concentrate of what to program rather than how to

program.

Memory Models

The RCM 3360 module has a 512 K of program execution SRAM, 512 K of data SRAM and 512 K of

flash memory [1]. The SRAM memory is used for compiling the program and running it in the SRAM helping us

save burning the flash again and again. The data SRAM is also used for allocating memory to the program as

and when required. If the design is not battery backed the data gets flushed out on power-cycle. The code is

burnt to the flash once the final design is finished and device is required to perform the necessary operation on

power-up. Having chosen a module with sufficient SRAM and flash space ensured that we have sufficient

memory for accommodating the large HTTP libraries required by our design.

Startup Code

As with any embedded system, all our peripherals need to be initialized on start up in the correct order.

The correct order of initialization is: Initializing the HTTP_Handler, followed by setting up the FAT file system

on the xD Card and then register the mounted partition with the zserver to upload files to using an ordinary web

browser. Once this is done, the Mp3 chip is initialized, the keypad interrupts vectors are setup and finally the

LCD is initialized and displays the welcome message signaling that initialization sequence has ended and the c|

r|u is ready to be used.

Organization of Embedded Code

For the purpose of modular software design, we organized the software for each of our design

components as separate libraries that could be imported easily using the “#use” directive. This made the code

much more readable and increased the ease of debugging the software manifold.

3

Page 4: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u

Software Design Narrative

LCD Module

The LCD is used to display useful information such as the current song title and artist’s name during

song playback. At other times, it also displays other information to inform the user of the device’s status at any

given point of time. The LCD uses an 8-bit parallel data bus interface on Port G to hook up to our

microprocessor. 3 other port pins are used on the processor to control the functioning of the LCD. PE1, PE3

and PF0 are used for controlling the R/W, EN and the RS port pins of the LCD respectively. The characters are

sent to the LCD one at a time and get decoded by the inbuilt controller and are appropriately displayed on the

LCD screen.

Keypad Encoder

The Keypad Encoder IC uses a 4 bit parallel interface to transfer key press information to the processor.

A single bit line called the Valid_Data generates an external interrupt to the processor on pin PE0 when the key

press has been encoded and valid data is available on the port pins for the processor to read. The ISR asserts a

flag stating that a Button has been pressed and buffers the port values for the program to read and perform the

necessary action.

STA013Mp3 Chip

The STA013 mp3 chip uses two different interfaces for its proper functioning. The commands like play,

mute, soft reset are sent to the chip over an I2C interface with pull up resistors on port PD6 and PD7 to act as

the SDA and the SCLK clock line. The mp3 data stream itself uses a SPI mechanism to send data over to the

chip which it then processes and send to the DAC converter for stereo level output. Port PC2 is used for the

serial data line and the port PF1 provides the serial clock.

Onboard xD Card Storage

The xD card(by Olympus) is formatted with a FAT system which makes reading and writing

Mp3 files easy. Using Dynamic C’s Fat library system, the effort required in communicating with device

required minimal understanding of control signals involved. Hence, no more details can be provided about this

module.

4

Page 5: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|uFlowchart

START

Init_HTTP

Init_LCDWelcome Screen

Init_MP3chip

UploadingMP3 File?

Send To Storage

Yes

Play pressed?

Retrieve fileSend to MP3

playbackSend ID3 to LCD

Y

End of song or Stop?

Clear MP3 and ResetY

No

HTTP Handler for Uploading MP3

No

5

Page 6: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|uSoftware Listing:

Http Handler and upload CGI(HTTP UPLD+FAT.C):

/**********************************************************************

This File hosts our web server and brings in a file form the client computer on the networks and writes them to the file “hello.mp3”

*******************************************************************************/#class auto

/*********************************** * Configuration * * ------------- * * All fields in this section must * * be altered to match your local * * network settings. * ***********************************/

/* * Pick the predefined TCP/IP configuration for this sample. See * LIB\TCPIP\TCP_CONFIG.LIB for instructions on how to set the * configuration. */

//#define TCPCONFIG 5

//#define USE_DHCP//#define IFCONFIG_ETH0 IFS_DHCP, 1, IFS_UP

#define MY_IP_ADDRESS "192.168.0.2"#define MY_GATEWAY "192.168.0.1"#define MY_NETMASK "255.255.255.0"

/* * TCP/IP modification - reduce TCP socket buffer * size, to allow more connections. This can be increased, * with increased performance, if the number of sockets * are reduced. Note that this buffer size is split in * two for TCP sockets--1024 bytes for send and 1024 bytes * for receive. */#define TCP_BUF_SIZE 2048

/* * Web server configuration */

/* * only one socket and server are needed for a reserved port

6

Page 7: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u */#define HTTP_MAXSERVERS 1#define MAX_TCP_SOCKET_BUFFERS 1

//#define HTTP_VERBOSE//#define ZSERVER_VERBOSE//#define HTTP_DEBUG//#define ZSERVER_DEBUG//#define DCRTCP_DEBUG

#define HTTP_TIMEOUT 6#define TESTFILE 1

// This macro causes the FAT library to wait for everything to complete// before returning to the caller. This makes the application MUCH simpler.#define FAT_BLOCK

// Uncomment to turn on Debug options//#define FAT_DEBUG//#define SFLASH_DEBUG//#define FATWTC_DEBUG//#define PART_DEBUG

/******************************** * End of configuration section * ********************************/

#define USE_HTTP_UPLOAD // Required for this demo, to include upload code.

#define DISABLE_DNS // No name lookups required

#memmap xmem

#use "dcrtcp.lib"#use "http.lib"#use "fs2.lib"#use "net.lib"#use rcm33xx.lib //sample library to use with this application

// Call in a device driver library. In this case, the serial flash.#use "sflash_fat.lib"// Call in the FAT filesystem support code.#use "fat.lib"

#define RIGHT 0#define LEFT 1#define ON 2#define OFF 3

#ximport "n:\testcode\upload.html" index_html//#ximport "n:\testcode\90kb.mp3" mp3_file

// We need some structures to contain the necessary information for FAT to// work.mbr_drvr my_driver;mbr_dev my_device;fat_part my_part;

7

Page 8: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u

// When files are accessed, we need a FATfile structure.FATfile my_file;

// This table maps file extensions to the appropriate "MIME" type. This is// needed for the HTTP server.SSPEC_MIMETABLE_START SSPEC_MIME(".htm", "text/html"), SSPEC_MIME(".html", "text/html"), SSPEC_MIME(".gif", "image/gif"), SSPEC_MIME(".cgi", "")SSPEC_MIMETABLE_END

// This is a buffer for reading/writing the file.char buf[512];

int rc; // Return code store. Always need to check return codes from // FAT library functions.long prealloc; // Used if the file needs to be created.

int finish;

void ReadFile(){ // Open the same file for reading. rc = fat_Open( &my_part, // Partition pointer as passed to fat_Init() "hello.mp3", // Name of file. Always an absolute path name. FAT_FILE, // Type of object, i.e. a file. 0, // 0 means the file must exist. &my_file, // Fill in this structure with file details NULL // This will not be used, you can pass NULL. );

if (rc < 0) { printf("fat_Open() (for read) failed with return code %d\n", rc); exit(1); }

// Read the first 128 bytes (sizeof buf) from the file. Of course, we // only wrote 15 characters so this will be all that can be read. // No matter, the return code indicates this. rc = fat_Read(&my_file, buf, sizeof(buf));

if (rc < 0) { printf("fat_Read() failed with return code %d\n", rc); } else { // Read OK. Print out the buffer contents. printf("Read %d bytes:\n", rc); printf("%*.*s", rc, rc, buf); // Print a string which is not NULL printf("\n"); // terminated. }

return;}

int upload_cgi(HttpState * s)8

Page 9: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u{ // OK, filesystem exists and is ready to access. Let's create a file.

// Do not pre-allocate any more than the minimum necessary amount of // storage.

prealloc = 0;

// Open (and maybe create) it... rc = fat_Open( &my_part, // Partition pointer as passed to fat_Init() "hello.mp3", // Name of file. Always an absolute path name. FAT_FILE, // Type of object, i.e. a file. FAT_CREATE, // Create the file if it does not exist. &my_file, // Fill in this structure with file details &prealloc // Number of bytes to allocate. );

if (rc < 0) { printf("MY FAT OPEN FAILED\n"); printf("fat_Open() failed with return code %d\n", rc); exit(1); }

if (!http_getState(s)) { http_setState(s, 1); printf("First entry:\n"); printf(" HTTP version=%s\n", http_getHTTPVersion(s) == HTTP_VER_09 ? "0.9" : http_getHTTPVersion(s) == HTTP_VER_10 ? "1.0" : http_getHTTPVersion(s) == HTTP_VER_11 ? "1.1" : "unknown"); printf(" HTTP method=%s\n", http_getHTTPMethod(s) == HTTP_METHOD_GET ? "GET" : http_getHTTPMethod(s) == HTTP_METHOD_POST ? "POST" : http_getHTTPMethod(s) == HTTP_METHOD_HEAD ? "HEAD" : "unknown"); printf(" Userid=%d\n", http_getContext(s)->userid); printf(" URL=%s\n", http_getURL(s)); }

switch (http_getAction(s)) { case CGI_PROLOG: printf("PROLOG \"%s\"\n", http_getData(s)); break; case CGI_HEADER: printf("HEADER \"%s\"\n", http_getData(s)); break; case CGI_START: printf("START content_length=%ld\n", http_getContentLength(s)); printf(" field name=%s\n", http_getField(s)); printf(" disposition=%d\n", http_getContentDisposition(s)); printf(" transfer_encoding=%d\n", http_getTransferEncoding(s)); printf(" content_type=%s\n", http_getContentType(s)); //if (strcmp(http_getContentType(s),"audio/mpeg") != 0) { // printf("\n\nNOT A MP3\n\n"); // skip = 1; //} break; case CGI_DATA: // Write to it... if (strcmp(http_getContentType(s),"audio/mpeg") == 0) { rc = fat_Write(

9

Page 10: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u &my_file, // File, as set by fat_Open() http_getData(s), // Some data to write. http_getDataLength(s) // Number of characters to write.

);

//fwrite(&file, http_getData(s), http_getDataLength(s));

if (rc < 0) { printf("MY FAT WRITE FAILED\n"); printf("fat_Write() failed with return code %d\n", rc); exit(1);

}

printf("DATA length=%d (total %ld) DATA = %s \n\n ", http_getDataLength(s), http_getContentLength(s), http_getDataLength(s)); } else { printf("\n\nNOT A MP3\n\n");

} break; case CGI_END: printf("END ----------- actual received length=%ld\n", http_getContentLength(s)); finish = 1; break; case CGI_EPILOG: printf("EPILOG \"%s\"\n", http_getData(s)); break; case CGI_EOF:

printf("EOF (unused content=%ld) \"%s\"\n", s->content_length, http_getData(s)); // Since we use switchCGI, there is no need to return CGI_DONE. http_switchCGI(s, "index.html"); break; case CGI_ABORT: printf("ABORT!\n"); break; default: printf("CGI: unknown action code %d\n", http_getAction(s)); break; } fat_Close(&my_file); return 0;}

// The flash resource table is now initialized with these macros...SSPEC_RESOURCETABLE_START SSPEC_RESOURCE_XMEMFILE("/index.html", index_html), //SSPEC_RESOURCE_XMEMFILE("/hello.mp3", mp3_file), SSPEC_RESOURCE_CGI("upload.cgi", upload_cgi)SSPEC_RESOURCETABLE_END

void main(){ char Message[15]; char Mac[25]; int i; finish = 0;

10

Page 11: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u

printf("Program starting...\n");

sock_init(); http_init(); tcp_reserveport(80);

http_set_path("/", "index.html");

// Initialize the FAT filesystem. The most important information is // put into "my_part" since, when you open a file, you need to specify // the partition. rc = fat_Init( 0, // Partition number. 0 is first partition. &my_driver, // This will be initialized... &my_device, // ...as will this... &my_part, // ...and this. 0 // 0 specifies normal crash recovery );

// FAT return codes always follow the convention that a negative value // indicates an error.

if (rc < 0) { // An error occurred. Here, we print out the numeric code. You can // look in lib\filesystem\errno.lib to see what type of error it // really is. Note that the values in errno.lib are the absolute // value of the return code. if (rc == -EUNFORMAT) printf("Device not Formatted, Please run Fmt_Device.c\n"); else

printf("fat_Init() failed with return code %d\n", rc); exit(1); }

rc = fat_CreateDir( &my_part, // fat_part

"\\A" );

if (rc < 0) { printf("PROBLEM HAHAHA !!!"); }

printf("INIT PASSED\n");

inet_ntoa(Message, _if_tab[IF_ETH0].ipaddr);

// pd_getaddress(0, Mac); // GETTING MAC ADDRESS // printf("MAC Address is %20x\n", Mac);

ip_print_ifs();

printf("\nEntering http handler\n"); while (1) { http_handler(); }

fat_Close(&my_file); printf("Reading file\n"); ReadFile();

11

Page 12: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u

printf("Out of HTTP HANDLER\n");

// Done writing; close it. rc = fat_Close(&my_file); printf("Closing FAT");

// Many programmers do not check the return code from "close". This is a // bad idea, since an error return code can indicate that data was lost! // Your application should be concerned about this... if (rc < 0) { printf("CLOSE FAILED\n"); printf("fat_Close() failed with return code %d\n", rc); // In this case, we soldier on to see if the file can be read. }

// Since we are using blocking mode, it will not return until it has // closed all files and unmounted the partition. fat_UnmountPartition(&my_part);

// Many operating systems do not like "hard reset/reboot" when a filesystem // is involved. The Rabbit FAT implementation is robust enough to // gracefully recover from reset/power loss without losing data. It will // automatically recover when fat_Init() is called at startup. However, it // is still a good idea to shut down properly if you know you are exiting // the program. printf("All OK.\n"); return;

}

LCD initialization and function definition(LCD.C):

/*******************************************************************This File initializes our LCD and defines functions that we will later use to

easily clear the display, write characters or initialized it in our main program.

*******************************************************************/

#class auto

#use rcm33xx.lib //sample library to use with this application

#define RIGHT 0#define LEFT 1#define ON 2#define OFF 3

////////////////////////////////////////////////////////////// provides milli-second delay///////////////////////////////////////////////////////////void msDelay(unsigned int delay){

auto unsigned long done_time;

done_time = MS_TIMER + delay; while( (long) (MS_TIMER - done_time) < 0 );

12

Page 13: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u}

////////////////////////////////////////////////////////////// LCD Initialization Routine///////////////////////////////////////////////////////////void InitLCD(void){

msDelay(18); BitWrPortI(PEDR, &PEDDRShadow, 1, 3); // Enabling msDelay(1);

WrPortI(PGDR, NULL, 48); msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 0, 3); // Disabling msDelay(5);

BitWrPortI(PEDR, &PEDDRShadow, 1, 3); // Enabling msDelay(1); WrPortI(PGDR, NULL, 48); msDelay(1);

BitWrPortI(PEDR, &PEDDRShadow, 0, 3); // Disabling

msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 1, 3); // Enabling

msDelay(1); WrPortI(PGDR, NULL, 48); msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 0, 3); // Disabling

msDelay(1);BitWrPortI(PEDR, &PEDDRShadow, 1, 3); // Enabling

msDelay(1); WrPortI(PGDR, NULL, 56); msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 0, 3); // Disabling

msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 1, 3); // Enabling msDelay(1); WrPortI(PGDR, NULL, 8); msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 0, 3); // Disabling WrPortI(PEDR, NULL, 0);

msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 1, 3); // Enabling

msDelay(1); WrPortI(PGDR, NULL, 1); msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 0, 3); // Disabling

msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 1, 3); // Enabling msDelay(1); WrPortI(PGDR, NULL, 4); msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 0, 3); // Disabling

msDelay(100); //initialization ends!!!

}13

Page 14: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u

////////////////////////////////////////////////////////////// Clears LCD Display///////////////////////////////////////////////////////////void ClearLCD(void){ // Sets DD RAM addres 0 in address counter // Display disappears and the cursor or blink // goes to the left edge of the display

BitWrPortI(PEDR, &PEDDRShadow, 1, 3); // Enabling WrPortI(PGDR, NULL, 1); BitWrPortI(PEDR, &PEDDRShadow, 0,0); BitWrPortI(PEDR, &PEDDRShadow, 0,1); msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 0,3); // Disabling msDelay(1);}

////////////////////////////////////////////////////////////// Return Home///////////////////////////////////////////////////////////void ReturnHome(void){ // Set DD RAM address to 0 in address counter // although contents don't change. Returns display // to its original status if it was shifted

BitWrPortI(PEDR, &PEDDRShadow, 1, 3); // Enabling WrPortI(PGDR, NULL, 0); BitWrPortI(PEDR, &PEDDRShadow, 0,0); BitWrPortI(PEDR, &PEDDRShadow, 0,1); msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 0,3); // Disabling msDelay(1);}

////////////////////////////////////////////////////////////// Entry Mode Set///////////////////////////////////////////////////////////void EntrySet(int IncDecCursor, int Shift){ // Sets the mode to increment or decrement the address // by one and to shift the cursor to the right or the // left at the time of write in DD/CGRAM

BitWrPortI(PEDR, &PEDDRShadow, 1, 3); //Enabling if (IncDecCursor == RIGHT) { if (Shift == RIGHT) { WrPortI(PGDR, NULL, 6); } else { WrPortI(PGDR, NULL, 2); } } else { if (Shift == RIGHT) { WrPortI(PGDR, NULL, 4); } else { WrPortI(PGDR, NULL, 0);

14

Page 15: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u } } BitWrPortI(PEDR, &PEDDRShadow, 0,0); BitWrPortI(PEDR, &PEDDRShadow, 0,1); msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 0,3); //Disabling msDelay(1);}

////////////////////////////////////////////////////////////// Shift Display : Left or Right///////////////////////////////////////////////////////////void DisplayShift(int shift){ // Shift display left or right BitWrPortI(PEDR, &PEDDRShadow, 1, 3); //Enabling if (shift == RIGHT) { WrPortI(PGDR, NULL, 28); } else { WrPortI(PGDR, NULL, 24); } BitWrPortI(PEDR, &PEDDRShadow, 0,0); BitWrPortI(PEDR, &PEDDRShadow, 0,1); msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 0,3); //Disabling msDelay(500);}

////////////////////////////////////////////////////////////// Display and Cursor ON/OFF///////////////////////////////////////////////////////////void DisplayOnOff(int DisplayOnOff, int CursorOnOff){ // Turns display ON or OFF BitWrPortI(PEDR, &PEDDRShadow, 1, 3); //Enabling if (DisplayOnOff == ON) { if (CursorOnOff == ON) { WrPortI(PGDR, NULL, 14); } else { WrPortI(PGDR, NULL, 12); } } else {

WrPortI(PGDR, NULL, 8); } BitWrPortI(PEDR, &PEDDRShadow, 0,0); BitWrPortI(PEDR, &PEDDRShadow, 0,1); msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 0,3); //Disabling msDelay(1);}

////////////////////////////////////////////////////////////// Function Set///////////////////////////////////////////////////////////void FunctionSet(int Line){

// 8 bit interface, 5x7 dots, 1 or 2 line displayBitWrPortI(PEDR, &PEDDRShadow, 1, 3); //Enabling

15

Page 16: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|uif (Line == 1) {

WrPortI(PGDR, NULL, 48); }

else {WrPortI(PGDR, NULL, 56);

} BitWrPortI(PEDR, &PEDDRShadow, 0,0); BitWrPortI(PEDR, &PEDDRShadow, 0,1); msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 0,3); //Disabling msDelay(1);}

////////////////////////////////////////////////////////////// Set Address///////////////////////////////////////////////////////////void SetAddress(int Address){ BitWrPortI(PEDR, &PEDDRShadow, 1,3); //Enabling WrPortI(PGDR, NULL, Address); BitWrPortI(PGDR, &PGDDRShadow, 1,7); BitWrPortI(PEDR, &PEDDRShadow, 0,0); BitWrPortI(PEDR, &PEDDRShadow, 0,1); msDelay(1); BitWrPortI(PEDR, &PEDDRShadow, 0,3); //Disabling msDelay(1);}

////////////////////////////////////////////////////////////// Write Character///////////////////////////////////////////////////////////void WriteCharacter(int Character){

BitWrPortI(PEDR, &PEDDRShadow, 1,3); //EnablingWrPortI(PGDR, NULL, Character);BitWrPortI(PEDR, &PEDDRShadow, 1,0);BitWrPortI(PEDR, &PEDDRShadow, 0,1);msDelay(1);BitWrPortI(PEDR, &PEDDRShadow, 0,3); //DisablingmsDelay(1);

}

void main(){

int i;char Message[28];

printf("Program starting...\n"); WrPortI(PGDDR, NULL, 0xff); WrPortI(PEDDR, NULL, 0xff);

InitLCD(); // Initializes LCD

FunctionSet(2); DisplayOnOff(ON, ON); EntrySet(RIGHT, RIGHT);

while(1) { printf("Enter the message to display on the LCD: ");

16

Page 17: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u gets(Message); ClearLCD(); msDelay(100); //WriteCharacter(' '); for(i = 0; i < strlen(Message); i++) { WriteCharacter(Message[i]); }

//while(1) { // DisplayShift(LEFT);

//} }

}

Keypad Encoder IC interface and initial debugging program(Keypad_ExtInterrupt.C):

/*****************************************************This program demonstrates how we use the interrupts to Bring in a keypad button press and determine what it is.Eventually we will use this as user input to control MP3 playback and other functions of the CRU.

******************************************************/#class auto

// Set equal to 1 to use fast interrupt in I&D space#define FAST_INTERRUPT 0

char count0;void my_isr0();

////////////////////////////////////////////////////////////// provides milli-second delay///////////////////////////////////////////////////////////void msDelay(unsigned int delay){

auto unsigned long done_time;

done_time = MS_TIMER + delay; while( (long) (MS_TIMER - done_time) < 0 );}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void main(){

count0 = 0;

WrPortI(PEDDR, &PEDDRShadow, 0x00); // set port E as all inputs17

Page 18: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u WrPortI(PGDDR, &PGDDRShadow, 0x00); // set Port G as all inputs

#if __SEPARATE_INST_DATA__ && FAST_INTERRUPTinterrupt_vector ext0_intvec my_isr0;

#elseSetVectExtern3000(0, my_isr0);

// re-setup ISR's to show example of retrieving ISR address using GetVectExtern3000SetVectExtern3000(0, GetVectExtern3000(0));

#endif

WrPortI(I0CR, &I0CRShadow, 0x05); // enable external INT0 on PE0, falling edge, priority 1

while (count0 < 20) {

// output the interrupt count every secondcostate {

//printf("counts = %3d\n", count0);//waitfor(DelaySec(1));

//}

}

WrPortI(I0CR, &I0CRShadow, 0x00); // disable external interrupt 0

// final countsprintf("counts = %3d\n", count0);

}

/****** interrupt routines ******/

nodebug root interrupt void my_isr0(){

//msDelay(20);printf("The reading on port G: %d\n",RdPortI(PGDR));count0++;

}

List of References

[1] Rabbit Semiconductor (Rabbit 3000 micro-controller)http://rabbitsemiconductor.com/documentation/docs/manuals/Rabbit3000/UsersManual R3000UM.pdf

18

Page 19: Introduction - Purdue Engineering · Web viewAll other peripherals interact with our central micro controller via on-chip software. Software Design Considerations The software design

Software Design Considerations c|r|u

[2] Dynamic C 9 User’s Manualhttp://rabbitsemiconductor.com/documentation/docs/manuals/DC/DCUserManual/index.htm

19