Hardware Reference
In-Depth Information
void main (void)
{
char i;
DDRM | 5 BIT5;
// configure PM5 pin for output
openspi0();
// configure SPI module properly
send_font(0x80);
// set font address pointer address to 0x00
for (i 5 0; i , 15; i 11 )
send_font(fonts[i]);
}
void send_font(char xx)
{
PTM & 5 , BIT5;
// enable SPI transfer
putcspi0(0x05);
// specify font address pointer
putcspi0(xx);
// send a font value
PTM | 5 BIT5;
// load data in shift register to destination
}
void openspi0(void)
{
SPI0BR 5 0x00; // set baud rate to 12 MHz
SPI0CR1 5 0x50; // disable interrupt, set master mode, shift data on
// rising edge, clock idle low
SPI0CR2 5 0x02; // disable mode fault, disable SPI in wait mode
WOMS 5 0;
// enable Port S pull-up
}
To display user-defined fonts, we need to send in the appropriate addresses in the range from
0x00 to 0x17. In Example 10.12, the addresses 0x00,0x02 should be used to access those three
special characters. The following C statements will display those three Chinese characters fol-
lowed by letters A, B, C, D, and E from left to right on the matrix displays shown in Figure 10.30:
sendtomax(0x20, 0x42, 0x20, 0x00); // 0x00 is the address of the first character font
sendtomax(0x21, 0x43, 0x21, 0x01); // 0x01 is the address of the second character font
sendtomax(0x22, 0x44, 0x22, 0x02); // 0x02 is the address of the third character font
sendtomax(0x23, 0x45, 0x23, 0x41);
10.13 Summary
When high-speed data transfer is not needed, using serial data transfer enables us to make
the most of the limited number of I/O pins available on the MCU device. Serial data transfer
can be performed asynchronously or synchronously. The SPI is a synchronous protocol created
by Freescale for serial data exchange between peripheral chips and microcontrollers.
In the SPI format, a device (must be a microcontroller) is responsible for initiating the data
transfer and generating the clock pulses for synchronizing data transfer. This device is referred
to as the SPI master . All other devices in the same system are referred to as SPI slaves . The
master device needs three signals to carry out the data transfer.
SCK: a clock signal for synchronizing data transfer
MOSI: serial data output from the master
MISO: serial data input to the master
 
Search WWH ::




Custom Search