Você está na página 1de 6

BinLibrary- Do-It- Yourself

2013

BinLibrary
http://binlibrary.blogspot.in

Read CID Register and Display on a PC Screen

http://binlibrary.blogspot.in

copyright@ BinLibrary 2013

BinLibrary- Do-It- Yourself

2013

In this project a SD card is interfaced to a PIC18F452-type microcontroller. The serial output port of the microcontroller is connected to the serial input port (e.g., COM1) of a PC. The microcontroller reads the contents of the card CID register and sends this data to the PC so it can be displayed on the PC screen.

PC

PIC 18f452 SD Card MAX 232

RS 232

Block diagram of the project

The circuit diagram of the project is shown in Figure 7.8. The SD card is inserted into a card holder and then connected to PORTC of a PIC18F452 microcontroller through 2.2K and 3.3K resistors, using the following pins: _ Card CS to PORTC pin RC2 _ Card CLK to PORTC pin RC3 _ Card DO to PORTC pin RC4 _ Card DI to PORTC pin RC5 According to the SD card specifications, when the card is operating with a supply voltage of VDD 3.3V, the input-output pin voltage levels are as follows: _ Minimum produced output HIGH voltage, VOH = 2.475V _ Maximum produced output LOW voltage, VOL = 0.4125V _ Minimum required input HIGH voltage, VIH = 2.0625 _ Maximum input HIGH voltage, VIH = 3.6V _ Maximum required input LOW voltage, VIL = 0.825V

http://binlibrary.blogspot.in

copyright@ BinLibrary 2013

BinLibrary- Do-It- Yourself

2013

Circuit Diagram

Although the output produced by the card (2.475V) is sufficient to drive the input port of a PIC microcontroller, the logic HIGH output of the microcontroller (about 4.3V) is too high for the SD card inputs (maximum 3.6V). Therefore, a potential divider is set up at the three inputs of the SD card using 2.2K and 3.3K resistors. This limits the maximum voltage at the inputs of the SD card to about 2.5V: SD card input voltage = 4.3V x 3.3K/(2.2K + 3.3K) = 2.48V Serial output port pin RC6 (TX) of the microcontroller is connected to a MAX232-type RS232 voltage level converter chip and then to a 9-way D-type connector so it can be connected to the serial input port of a PC. The microcontroller is powered from a 5V supply which is obtained via a 7805-type 5V regulator with a 9V input. The 2.7V3.6V supply required by the SD card is obtained via an MC33269DT-3.3 regulator with 3.3V output and is driven from the 5V input voltage. The program listing of the project is given in Figure 7.9 (program SD1.C). At the beginning of the main program, character array CID is declared to have 16 bytes.

Program
http://binlibrary.blogspot.in copyright@ BinLibrary 2013

BinLibrary- Do-It- Yourself

2013

/*************************************************************/ SD CARD PROJECT =============== In this project a SD card is connected to PORTC as follows: CS RC2 CLK RC3 DO RC4 DI RC5 In addition, a MAX232 type RS232 voltage level converter chip is connected to serial output port RC6. The program reads the SD card CID register parameters and sends it to a PC via the serial interface. This process is repeated at every 10 seconds. The UART is set to operate at 2400 Baud, 8 bits, no parity. / // // This function sends carriage-return and line-feed to USART // void Newline() { Soft_Uart_Write(0x0D); // Send carriage-return Soft_Uart_Write(0x0A); // Send line-feed } // // This function sends a space character to USART // void Space() { Soft_Uart_Write(0x20); } // // This function sends a text to serial port // void Text_To_Usart(unsigned char m) { unsigned char i; i = 0; while(m[i] != 0) { // Send TEXT to serial port Soft_Uart_Write(m[i]); i++; } } //

http://binlibrary.blogspot.in

copyright@ BinLibrary 2013

BinLibrary- Do-It- Yourself

2013

// This function sends string to serial port. The string length is passed as an argument // void Str_To_Usart(unsigned char m,unsigned char 1) { unsigned char i; unsigned char txt[4]; i=0; for(i=0; i<l; i++) { ByteToStr(m[i],txt); Text_To_Usart(txt); Space(); } } // // Start of MAIN program // void main() { unsigned char error,CID[16]; unsigned char msg[] = " SD CARD CID REGISTER"; // // Configure the serial port // Soft_Uart_Init(PORTC,7,6,2400,0); // TX=RC6 // // Initialise the SD card // Spi_Init_Advanced(MASTER_OSC_DIV16,DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH); // // Initialise the SD bus // while(Mmc_Init(&PORTC,2)); // // Start of MAIN loop. Read the SD card CID register and send the data // to serial port every 10 seconds // for(;;) // Endless loop { Text_To_Usart(msg); // Send TEXT Newline(); // Send newline Newline(); // Send newline

http://binlibrary.blogspot.in

copyright@ BinLibrary 2013

BinLibrary- Do-It- Yourself

2013

error = Mmc_Read_Cid(CID); // Read CID register into CID // // Send the data to RS232 port // Str_To_Usart(CID,16); // Send CID contents to UART Delay_Ms(10000); // Wait 10 seconds Newline(); Newline(); } }

Define:
Variable msg is loaded with the message that is to be displayed when power is applied to the system. Then the UART is initialized at PORTC with a baud rate of 2400. Before the SD card library functions are used, the function Spi_Init_Advanced must be called with the given arguments. Then the SD card bus is initialized by calling function Mmc_Init, where it is specified that the card is connected to PORTC. The program then enters an endless loop that repeats every ten seconds. Inside this loop the heading message is displayed followed by two new-line characters. The program then reads the contents of register CID by calling function Mmc_Read_Cid and stores the data in character array CID. The data is then sent to the serial port by calling function Str_To_Usart. At the end of the loop two new-line characters are displayed, the program waits for ten seconds, and the loop is repeated. The operation of the project can be tested by connecting the device to a PC and starting the HyperTerminal terminal emulation program on the PC. Set the communications parameters to 2400 baud, 8 data bits, 1 stop bit, and no parity bit.

http://binlibrary.blogspot.in

copyright@ BinLibrary 2013

Você também pode gostar