Lab 4 Report: Digital Signal Processing
Lab 4 Report: Digital Signal Processing
LAB 4 REPORT
File transceiving
Using TMS320C5515 eZDSPTM USB Stick
Group 7:
Dat Nguyen-Si ID: ILI11006 In-class ID: 2
Trung Le ID: 41103857 In-class ID: 3
Introduction....................................................................3
Source codes..................................................................8
Conclusion....................................................................14
References....................................................................15
1 Lab 4 report
Abstract
This report introduces how to read and write a March, 27th 2014
file to the computer’s drive using the
TMS320C5515 eZDSPTM USB Stick Development
Tool. The goal of this lab is to read a text file on
the computer’s drive and display them to the
compiler’s console as well as on the LCD of the
kit.
2. Read the file specified by its path then display its content on the LCD of the board and
the CCS console.
The LCD module in the TMS320C5515 eZDSPTM USB Stick Development Tool is a 96×16
monochrome OLED display screen. LCD can be a very useful part in any microcontroller
based project. It helps to monitor variables and program status with simple texts or
numbers.
3 TMS320C5515 eZdsp™ USB Stick Development Tool’s LCD module Lab 4 report
Overview of file functions in stdio.h library [1]
fopen()
March, 27th 2014
Declaration:
Opens the filename pointed to by filename. The mode argument may be one of the following
constant strings:
w write text mode (truncates file to zero length or creates new file)
a append text mode for writing (opens or creates file and sets file pointer to the end-of-file)
wb write binary mode (truncates file to zero length or creates new file)
ab append binary mode for writing (opens or creates file and sets file pointer to the end-of-file)
a+ read and write text mode (opens or creates file and sets file pointer to the end-of-file)
w+b or wb+ read and write binary mode (truncates file to zero length or creates new file)
a+b or ab+ read and write binary mode (opens or creates file and sets file pointer to the end-of-
file)
If the file does not exist and it is opened with read mode (r), then the open fails.
If the file is opened with append mode (a), then all write operations occur at the end of the file
regardless of the current file position.
If the file is opened in the update mode (+), then output cannot be directly followed by input and
input cannot be directly followed by output without an intervening fseek, fsetpos, rewind, or fflush.
On success a pointer to the file stream is returned. On failure a null pointer is returned.
fseek()
Declaration:
Sets the file position of the stream to the given offset. The argument offset signifies the number of
March, 27th 2014
bytes to seek from the given whence position. The argument whence can be:
On a text stream, whence should be SEEK_SET and offset should be either zero or a value returned
from ftell.
fread()
Declaration:
5 size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); Lab 4 report
Reads data from the given stream into the array pointed to by ptr. It reads nmemb number of
elements of size size. The total number of bytes read is (size*nmemb).
On success the number of elements read is returned. On error or end-of-file the total number of
elements successfully read (which may be zero) is returned.
fwrite()
Declaration:
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
Writes data from the array pointed to by ptr to the given stream. It writes nmemb number of
elements of size size. The total number of bytes written is (size*nmemb).
On success the number of elements writen is returned. On error the total number of elements
successfully writen (which may be zero) is returned.
fgetc()
Declaration:
Gets the next character (an unsigned char) from the specified stream and advances the position
March, 27th 2014
indicator for the stream.
On success the character is returned. If the end-of-file is encountered, then EOF is returned and the
end-of-file indicator is set. If an error occurs then the error indicator for the stream is set and EOF is
returned.
feof()
Declaration:
Tests the end-of-file indicator for the given stream. If the stream is at the end-of-file, then it returns
a nonzero value. If it is not at the end of the file, then it returns zero.
fclose()
6 Lab 4 report
Declaration:
0
1
2
3
4
5
6
4
5
6
7
8
9
0
1
2
3
7
8
9
4
5
6
7
8
9
7 0th column (0th element of the array) Lab 4 report
4th column
1st column
2nd column
3rd column
5th column
6th column
7th column
8th column 1st column
9th column 2nd column
3rd column
4th column
5th column
6th column
7th column
This way, we are not limited to 128 columns as it only depends on the size of the array we
set up (which can extend to infinite). The result animation is very smooth as the time
interval between each print is very small, which makes our eyes perceive the animation as a
smooth scrolling.
Source codes
In this source code, for convenience, we print each letter from left to right. March,
Compare27thto2014
the
sample code, there are 2 difference:
#include"usbstk5515.h"
#include"usbstk5515_i2c.h"
#include"usbstk5515_gpio.h"
#include"lcd.h"
#include <stdio.h>
#include <string.h>
#include "usbstk5515.h"
8 Lab 4 report
#define OSD9616_I2C_ADDR 0x3C // OSD9616 I2C address
//
//
///* ------------------------------------------------------------------------ *
// * *
// * Int16 OSD9616_send( Uint16 comdat, Uint16 data ) *
// * *
// * Sends 2 bytes of data to the OSD9616 *
// * *
// * ------------------------------------------------------------------------ */
Int16 OSD9616_send( Uint16 comdat, Uint16 data )
{
Uint8 cmd[2];
cmd[0] = comdat & 0x00FF; // Specifies whether data is Command or Data
cmd[1] = data; // Command / Data
/* ------------------------------------------------------------------------ *
* *
* Int16 OSD9616_multiSend( Uint16 comdat, Uint16 data ) *
* *
* Sends multiple bytes of data to the OSD9616 *
* *
* ------------------------------------------------------------------------ */
Int16 OSD9616_multiSend( Uint8* data, Uint16 len )
{
Uint16 x;
Uint8 cmd[10];
for(x=0;x<len;x++) // Command / Data
{
cmd[x] = data[x];
} March, 27th 2014
return USBSTK5515_I2C_write( OSD9616_I2C_ADDR, cmd, len );
}
/* ------------------------------------------------------------------------ *
* *
* Int16 printLetter(Uint16 l1,Uint16 l2,Uint16 l3,Uint16 l4) *
* *
* Send 4 bytes representing a Character *
* *
* ------------------------------------------------------------------------ */
Int16 printLetter(Uint16 l1,Uint16 l2,Uint16 l3,Uint16 l4)
{
OSD9616_send(0x40,l4);
OSD9616_send(0x40,l3);
OSD9616_send(0x40,l2);
OSD9616_send(0x40,l1);
OSD9616_send(0x40,0x00);
return 0;
}
//
///* ------------------------------------------------------------------------ *
// * *
// * Int16 oled_test() *
// * *
// * Testing function for the OSD9616 display *
// * *
// * ------------------------------------------------------------------------ */
Int16 oled_test()
{
Int16 i,j,length;
Uint8 cmd[10]; // For multibyte commands
/* Initialize I2C */
USBSTK5515_I2C_init( );
OSD9616_send(0x00,0x2e);//Deactivate scrolling
FILE *fp;
char buffer[100];
char myText[500];
int c;
/* Open file for both reading and writing */
fp = fopen("D:\\in1.txt", "r");
while (1)
{ March, 27th 2014
c=fgetc(fp);
if(feof(fp))
{
break;
}
length++;
}
fp = fopen("D:\\in1.txt", "r");
fread(buffer,length, 1, fp);
printf("%s\n", buffer);
for (i=0;i<length+1;i++)
for (j=0;j<5;j++)
myText[i*5+j]=Ascii[buffer[i]-32][j];
/* Write to page 0 */
// length=strlen(c)+1;
/* Open file for both reading and writing */
fp = fopen("D:\\dat.txt","w+");
/* Write data to the file */
fwrite(buffer, length + 1, 1, fp);
13 fclose(fp); Lab 4 report
/*display on LCD*/
for(j=0;j<=length*5-1-95;j++)
{
OSD9616_send(0x00,0x00); // Set low column address =32d
OSD9616_send(0x00,0x12); // Set high column address
OSD9616_send(0x00,0xb0+0); // Set page for page 0 to page 5
for(i=j;i<j+95;i++) OSD9616_send(0x40,myText[i]);
if (j==(length*5-1-95)) j=0;
}
return(0);
}
Conclusion
In this lab, we succeed to achieve the goal of the lab. The results are as shown: March, 27th 2014
14 Lab 4 report
References
[1] Detailed instructions of stdio.h C library are acquired from
March, 27th 2014
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.12.html
[2] Detailed instructions of OLED SSD 1306 driver are taken from the SSD1306.pdf acquired from
www.adafruit.com/datasheets/SSD1306.pdf .
Illustrating images of C5515 eZDSP USB Stick Development Tool are taken from
http://www.ti.com/tool/tmdx5515ezdsp.
All source codes in this report are taken from the usbstk5515_v1 library associated with
C5515 eZDSP USB Stick Development Tool, provided by Spectrum Digital Inc..
15 Lab 4 report