|
你要串行的还是并行的?
- #include <TM4C.h>
- #include <stdint.h>
- #include <stdbool.h>
- #include "inc/hw_ints.h"
- #include "inc/hw_memmap.h"
- #include "inc/hw_types.h"
- #include "driverlib/sysctl.h"
- #include "driverlib/interrupt.h"
- #include "driverlib/gpio.h"
- #include "driverlib/timer.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define Delay_us(x) SysCtlDelay((long)(SysCtlClockGet( )*(double)x /3000000 ))
- #define Delay_ms(x) SysCtlDelay((long)(SysCtlClockGet( )*(double)x /3000 ))
- #define SCLK_H GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_4,0Xff )
- #define SCLK_L GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_4,0x00 )
- #define CS_H GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2,0xFF )
- #define CS_L GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2,0x00 )
- #define SID_H GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3,0xff )
- #define SID_L GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3,0x00 )
- #define SID GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_3)
- /********************************************************************
- *??: sendbyte()
- *??:???????????,????
- *??: zdata
- *??:?
- ***********************************************************************/
- void sendbyte(unsigned char zdata)
- {
- unsigned int i;
- for(i=0;i<8;i++)
- {
- if((zdata << i) & 0x80)
- {
- SID_H;//SID=1;
- }
- else
- {
- SID_L;//SID=0;
- }
- SCLK_L;//SCLK= 0;
- SCLK_H;//SCLK=1;
- }
- }
- /********************************************************************
- *??: write_com()
- *??:?????
- *??: cmdcode
- *??:?
- **********************************************************************/
- void write_com(unsigned char cmdcode)
- {
- CS_H;//CS=1;
- sendbyte(0xf8); //??12864???????
- sendbyte(cmdcode & 0xf0);
- sendbyte((cmdcode << 4) & 0xf0);
- Delay_us(200);
- }
- /********************************************************************
- *??: write_data()
- *??:?????
- *??: cmdcode
- *??:?
- ***********************************************************************/
- void write_data(unsigned char Dispdata)
- {
- CS_H;//CS=1;
- sendbyte(0xfa); //??12864???????
- sendbyte(Dispdata & 0xf0);
- sendbyte((Dispdata << 4) & 0xf0);
- Delay_us(200);
- }
- /********************************************************************
- *??: lcdinit()
- *??:?????
- *??: cmdcode
- *??:?
- ***********************************************************************/
- void lcdinit()
- {
- Delay_ms(20);
- write_com(0x30); //??????
- Delay_ms(5) ;
- write_com(0x0c); //???????
- Delay_ms(5) ;
- }
- /********************************************************************
- *??: hzkdis()
- *??:?????
- *??: *s
- *??:?
- *********************************************************************/
- void hzkdis(char *s)
- {
- while(*s > 0)
- {
- write_data(*s);
- s++;
- Delay_ms(5);
- }
- }
- /********************************************************************
- *??: Test()
- *??:?????
- *??:?
- *??:?
- ***********************************************************************/
- void Test()
- {
- write_com(0x03); //????
- Delay_ms(5);
- write_com(0x81); //?????
- hzkdis("555");
- write_com(0x91); //?????
- hzkdis("5");
- }
- /********************************************************************
- *??: Main()
- *??:???
- *??:?
- *??:?
- **********************************************************************/
- int main(void)
- {
- SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
- GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
- GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4);
- GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x08);
- Delay_ms(20);
- lcdinit();
- Delay_ms(20);
- while(1)
- {
- Test();
- Delay_ms(50);
- }
- }
复制代码
上面是串行的
你先看一下
其实时序什么的都不是很难 |
|