Leonid Horburov / Mbed 2 deprecated Nucleo_lab5

Dependencies:   mbed NewTextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "NewTextLCD.h"
00003 DigitalOut rs(D12);
00004 DigitalOut e(D11);
00005 DigitalOut d0(D10);
00006 DigitalOut d1(D9);
00007 DigitalOut d2(D8);
00008 DigitalOut d3(D7);
00009 DigitalOut d4(D6);
00010 DigitalOut d5(D5);
00011 DigitalOut d6(D4);
00012 DigitalOut d7(D3);
00013 
00014 void write_data_to_port(uint8_t data)
00015 {
00016     d0=((data>>0)& 0x01);
00017     d1=((data>>1)& 0x01);
00018     d2=((data>>2)& 0x01);
00019     d3=((data>>3)& 0x01);
00020     d4=((data>>4)& 0x01);
00021     d5=((data>>5)& 0x01);
00022     d6=((data>>6)& 0x01);
00023     d7=((data>>7)& 0x01);
00024 }
00025 void send_data(uint8_t data)
00026 {
00027     rs=1;
00028     write_data_to_port(data);
00029     e=1;
00030     wait(0.04f);
00031     e=0;
00032 }
00033 
00034 void send_command(uint8_t command)
00035 {
00036     rs=0;
00037     write_data_to_port(command);
00038     e=1;
00039     wait(0.04f);
00040     e=0;
00041 }
00042 
00043 void init_lcd(void)
00044 {
00045     wait(0.02f);
00046     send_command(0b00110000);
00047     send_command(0b00110000);
00048     send_command(0b00110000);
00049     send_command(0b00111000);
00050     send_command(0b00001111);
00051     send_command(0b00000001);
00052     send_command(0b00000110);
00053     send_command(0b00000010);
00054 }
00055 
00056 void lcd_set_address(uint8_t address)
00057 {
00058     send_command(0b10000000 | address);
00059 }
00060 
00061 void write_string(char * str)
00062 {
00063     do {
00064         send_data(*str);
00065     } while (*++str);
00066 }
00067 
00068 void clear_string()
00069 {
00070    int clear=80;
00071    
00072    for(int i=0; i<(clear);i++){
00073        write_string(" ");
00074        }
00075 }
00076 
00077 
00078 
00079 int main()
00080 {
00081    
00082     init_lcd();
00083     while(1){
00084     write_string("405 A");
00085     clear_string();
00086     for(int i=0; i<6;i++){
00087     write_string(" ");
00088     }
00089     write_string("405 A");
00090     clear_string();
00091     for(int i=0; i<19;i++){
00092     write_string(" ");
00093     }
00094     write_string("405 A");
00095     clear_string();
00096     }
00097 }