1 | #include "HD4470.h"
|
2 | #include "stm32f10x_conf.h"
|
3 | #include "Delay.h"
|
4 | #include <string.h>
|
5 |
|
6 | void HD4470_init(void);
|
7 | void HD4470_clear(void);
|
8 | void HD4470_command(int bits, int char_mode);
|
9 | void HD4470_sprint(char text[]);
|
10 |
|
11 | void HD4470_init(void){
|
12 |
|
13 | GPIO_InitTypeDef GPIO_InitStructure;
|
14 | //PORT A
|
15 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
16 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
17 | GPIO_InitStructure.GPIO_Pin = LCD_Command_RS | LCD_Command_RW | LCD_Command_E;
|
18 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
19 | GPIO_Init(GPIOA,&GPIO_InitStructure);
|
20 | //PORT B
|
21 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
22 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
23 | GPIO_InitStructure.GPIO_Pin = LCD_DataBit_4 | LCD_DataBit_5 | LCD_DataBit_6 | LCD_DataBit_7;
|
24 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
25 | GPIO_Init(GPIOB,&GPIO_InitStructure);
|
26 |
|
27 | HD4470_clear();
|
28 | }
|
29 |
|
30 | void HD4470_clear(void){
|
31 | HD4470_command(0x33,0);
|
32 | HD4470_command(0x32,0);
|
33 | HD4470_command(0x06,0);
|
34 | HD4470_command(0x0C,0);
|
35 | HD4470_command(0x28,0);
|
36 | HD4470_command(0x01,0);
|
37 | }
|
38 |
|
39 | void HD4470_command(int bits, int char_mode){
|
40 | if(char_mode!=1)char_mode=0; //wenn charmode nicht explizit 1 ist, muss es 0 sein
|
41 | GPIO_WriteBit(LCD_Command_RS_PORT,LCD_Command_RS,DISABLE);
|
42 | GPIO_WriteBit(LCD_Command_RW_PORT,LCD_Command_RW,DISABLE);
|
43 | Delay_Ms(1);
|
44 |
|
45 | GPIO_WriteBit(LCD_DataBit_4_PORT,LCD_DataBit_4,DISABLE);
|
46 | GPIO_WriteBit(LCD_DataBit_5_PORT,LCD_DataBit_5,DISABLE);
|
47 | GPIO_WriteBit(LCD_DataBit_6_PORT,LCD_DataBit_6,DISABLE);
|
48 | GPIO_WriteBit(LCD_DataBit_7_PORT,LCD_DataBit_7,DISABLE);
|
49 |
|
50 | GPIO_WriteBit(LCD_DataBit_4_PORT,LCD_DataBit_4,(bits>>4)&0x01);
|
51 | GPIO_WriteBit(LCD_DataBit_5_PORT,LCD_DataBit_5,(bits>>5)&0x01);
|
52 | GPIO_WriteBit(LCD_DataBit_6_PORT,LCD_DataBit_6,(bits>>6)&0x01);
|
53 | GPIO_WriteBit(LCD_DataBit_7_PORT,LCD_DataBit_7,(bits>>7)&0x01);
|
54 |
|
55 | // start transmission
|
56 | Delay_us(1);
|
57 | GPIO_WriteBit(LCD_Command_E_PORT,LCD_Command_E,ENABLE);
|
58 | Delay_us(1);
|
59 | GPIO_WriteBit(LCD_Command_E_PORT,LCD_Command_E,DISABLE);
|
60 |
|
61 | GPIO_WriteBit(LCD_DataBit_4_PORT,LCD_DataBit_4,(bits>>0)&0x01);
|
62 | GPIO_WriteBit(LCD_DataBit_5_PORT,LCD_DataBit_5,(bits>>1)&0x01);
|
63 | GPIO_WriteBit(LCD_DataBit_6_PORT,LCD_DataBit_6,(bits>>2)&0x01);
|
64 | GPIO_WriteBit(LCD_DataBit_7_PORT,LCD_DataBit_7,(bits>>3)&0x01);
|
65 |
|
66 | // start transmission
|
67 | Delay_us(1);
|
68 | GPIO_WriteBit(LCD_Command_E_PORT,LCD_Command_E,ENABLE);
|
69 | Delay_us(1);
|
70 | GPIO_WriteBit(LCD_Command_E_PORT,LCD_Command_E,DISABLE);
|
71 |
|
72 | }
|
73 |
|
74 | void HD4470_sprint(char text[]){
|
75 | /*for(int i=0; i < strlen(text); ++i){
|
76 | cmd(text[i],1);
|
77 | }*/
|
78 | int i=0;
|
79 | while(i < strlen(text)){
|
80 | HD4470_command(text[i],1);
|
81 | ++i;
|
82 | }
|
83 |
|
84 | }
|