4rf4rf5r

Dependencies:   mbed NewTextLCD

Committer:
hobro
Date:
Mon Nov 04 12:39:02 2019 +0000
Revision:
0:48d6d554482e
lab5;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hobro 0:48d6d554482e 1 #include "mbed.h"
hobro 0:48d6d554482e 2 #include "NewTextLCD.h"
hobro 0:48d6d554482e 3 DigitalOut rs(D12);
hobro 0:48d6d554482e 4 DigitalOut e(D11);
hobro 0:48d6d554482e 5 DigitalOut d0(D10);
hobro 0:48d6d554482e 6 DigitalOut d1(D9);
hobro 0:48d6d554482e 7 DigitalOut d2(D8);
hobro 0:48d6d554482e 8 DigitalOut d3(D7);
hobro 0:48d6d554482e 9 DigitalOut d4(D6);
hobro 0:48d6d554482e 10 DigitalOut d5(D5);
hobro 0:48d6d554482e 11 DigitalOut d6(D4);
hobro 0:48d6d554482e 12 DigitalOut d7(D3);
hobro 0:48d6d554482e 13
hobro 0:48d6d554482e 14 void write_data_to_port(uint8_t data)
hobro 0:48d6d554482e 15 {
hobro 0:48d6d554482e 16 d0=((data>>0)& 0x01);
hobro 0:48d6d554482e 17 d1=((data>>1)& 0x01);
hobro 0:48d6d554482e 18 d2=((data>>2)& 0x01);
hobro 0:48d6d554482e 19 d3=((data>>3)& 0x01);
hobro 0:48d6d554482e 20 d4=((data>>4)& 0x01);
hobro 0:48d6d554482e 21 d5=((data>>5)& 0x01);
hobro 0:48d6d554482e 22 d6=((data>>6)& 0x01);
hobro 0:48d6d554482e 23 d7=((data>>7)& 0x01);
hobro 0:48d6d554482e 24 }
hobro 0:48d6d554482e 25 void send_data(uint8_t data)
hobro 0:48d6d554482e 26 {
hobro 0:48d6d554482e 27 rs=1;
hobro 0:48d6d554482e 28 write_data_to_port(data);
hobro 0:48d6d554482e 29 e=1;
hobro 0:48d6d554482e 30 wait(0.04f);
hobro 0:48d6d554482e 31 e=0;
hobro 0:48d6d554482e 32 }
hobro 0:48d6d554482e 33
hobro 0:48d6d554482e 34 void send_command(uint8_t command)
hobro 0:48d6d554482e 35 {
hobro 0:48d6d554482e 36 rs=0;
hobro 0:48d6d554482e 37 write_data_to_port(command);
hobro 0:48d6d554482e 38 e=1;
hobro 0:48d6d554482e 39 wait(0.04f);
hobro 0:48d6d554482e 40 e=0;
hobro 0:48d6d554482e 41 }
hobro 0:48d6d554482e 42
hobro 0:48d6d554482e 43 void init_lcd(void)
hobro 0:48d6d554482e 44 {
hobro 0:48d6d554482e 45 wait(0.02f);
hobro 0:48d6d554482e 46 send_command(0b00110000);
hobro 0:48d6d554482e 47 send_command(0b00110000);
hobro 0:48d6d554482e 48 send_command(0b00110000);
hobro 0:48d6d554482e 49 send_command(0b00111000);
hobro 0:48d6d554482e 50 send_command(0b00001111);
hobro 0:48d6d554482e 51 send_command(0b00000001);
hobro 0:48d6d554482e 52 send_command(0b00000110);
hobro 0:48d6d554482e 53 send_command(0b00000010);
hobro 0:48d6d554482e 54 }
hobro 0:48d6d554482e 55
hobro 0:48d6d554482e 56 void lcd_set_address(uint8_t address)
hobro 0:48d6d554482e 57 {
hobro 0:48d6d554482e 58 send_command(0b10000000 | address);
hobro 0:48d6d554482e 59 }
hobro 0:48d6d554482e 60
hobro 0:48d6d554482e 61 void write_string(char * str)
hobro 0:48d6d554482e 62 {
hobro 0:48d6d554482e 63 do {
hobro 0:48d6d554482e 64 send_data(*str);
hobro 0:48d6d554482e 65 } while (*++str);
hobro 0:48d6d554482e 66 }
hobro 0:48d6d554482e 67
hobro 0:48d6d554482e 68 void clear_string()
hobro 0:48d6d554482e 69 {
hobro 0:48d6d554482e 70 int clear=80;
hobro 0:48d6d554482e 71
hobro 0:48d6d554482e 72 for(int i=0; i<(clear);i++){
hobro 0:48d6d554482e 73 write_string(" ");
hobro 0:48d6d554482e 74 }
hobro 0:48d6d554482e 75 }
hobro 0:48d6d554482e 76
hobro 0:48d6d554482e 77
hobro 0:48d6d554482e 78
hobro 0:48d6d554482e 79 int main()
hobro 0:48d6d554482e 80 {
hobro 0:48d6d554482e 81
hobro 0:48d6d554482e 82 init_lcd();
hobro 0:48d6d554482e 83 while(1){
hobro 0:48d6d554482e 84 write_string("405 A");
hobro 0:48d6d554482e 85 clear_string();
hobro 0:48d6d554482e 86 for(int i=0; i<6;i++){
hobro 0:48d6d554482e 87 write_string(" ");
hobro 0:48d6d554482e 88 }
hobro 0:48d6d554482e 89 write_string("405 A");
hobro 0:48d6d554482e 90 clear_string();
hobro 0:48d6d554482e 91 for(int i=0; i<19;i++){
hobro 0:48d6d554482e 92 write_string(" ");
hobro 0:48d6d554482e 93 }
hobro 0:48d6d554482e 94 write_string("405 A");
hobro 0:48d6d554482e 95 clear_string();
hobro 0:48d6d554482e 96 }
hobro 0:48d6d554482e 97 }