Pão de Queijo Development Board. This repo has all libraries from pqdb shield.
Pão de Queijo development board is a shield for add-on on any arduino compatible board.
This project presents the libraries to control the board peripherals using mbed framework. The libraries works as interfaces to keep the main code compatible with the examples from the book "Programação de sistemas embarcados". The peripherals on the board are presented on the folowing picture
The main objective of the project is to develop a low cost, easy to assemble board with a group of peripheral that allows one to start learning embedded systems. The board was routed on one side copper PCB to make easier to buid it yourself.
The source code for Arduino boards (wiring) can be found on: https://github.com/projetopqdb/PQDB-Arduino
The source code for freedom frdm KL05 board (using direct register access) can be found on: https://github.com/projetopqdb/PQDB-KL05Z
The source code from the board schematics and layout can be found on: https://github.com/projetopqdb/PQDB-Hardware
lcd.cpp@6:3fb450ba1e95, 2017-10-03 (annotated)
- Committer:
- rmaalmeida
- Date:
- Tue Oct 03 01:27:24 2017 +0000
- Revision:
- 6:3fb450ba1e95
- Parent:
- 1:083267bc0a0e
timer driver added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rmaalmeida | 1:083267bc0a0e | 1 | #include "so.h" |
rmaalmeida | 1:083267bc0a0e | 2 | //#include "io.h" |
rmaalmeida | 1:083267bc0a0e | 3 | #include "lcd.h" |
rmaalmeida | 1:083267bc0a0e | 4 | #include "mbed.h" |
rmaalmeida | 1:083267bc0a0e | 5 | #include "ssd.h" |
rmaalmeida | 1:083267bc0a0e | 6 | //#define LCD_RS_PIN 7 |
rmaalmeida | 1:083267bc0a0e | 7 | //#define LCD_EN_PIN 6 |
rmaalmeida | 1:083267bc0a0e | 8 | |
rmaalmeida | 1:083267bc0a0e | 9 | DigitalOut LCD_RS_PIN(D7); |
rmaalmeida | 1:083267bc0a0e | 10 | DigitalOut LCD_EN_PIN(D6); |
rmaalmeida | 1:083267bc0a0e | 11 | |
rmaalmeida | 1:083267bc0a0e | 12 | |
rmaalmeida | 1:083267bc0a0e | 13 | //Gera um clock no enable |
rmaalmeida | 1:083267bc0a0e | 14 | void pulseEnablePin() { |
rmaalmeida | 1:083267bc0a0e | 15 | //digitalWrite(LCD_EN_PIN, HIGH); |
rmaalmeida | 1:083267bc0a0e | 16 | LCD_EN_PIN =1; |
rmaalmeida | 1:083267bc0a0e | 17 | //wait_us(5); |
rmaalmeida | 1:083267bc0a0e | 18 | //digitalWrite(LCD_EN_PIN, LOW); |
rmaalmeida | 1:083267bc0a0e | 19 | LCD_EN_PIN = 0; |
rmaalmeida | 1:083267bc0a0e | 20 | // wait_us(5); |
rmaalmeida | 1:083267bc0a0e | 21 | } |
rmaalmeida | 1:083267bc0a0e | 22 | //Envia 4 bits e gera um clock no enable |
rmaalmeida | 1:083267bc0a0e | 23 | void pushNibble(char value, int rs) { |
rmaalmeida | 1:083267bc0a0e | 24 | ssdOff(); |
rmaalmeida | 1:083267bc0a0e | 25 | soWrite(value); |
rmaalmeida | 1:083267bc0a0e | 26 | //digitalWrite(LCD_RS_PIN, rs); |
rmaalmeida | 1:083267bc0a0e | 27 | LCD_RS_PIN = rs; |
rmaalmeida | 1:083267bc0a0e | 28 | pulseEnablePin(); |
rmaalmeida | 1:083267bc0a0e | 29 | } |
rmaalmeida | 1:083267bc0a0e | 30 | //Envia 8 bits em dois pacotes de 4 |
rmaalmeida | 1:083267bc0a0e | 31 | void pushByte(char value, int rs) { |
rmaalmeida | 1:083267bc0a0e | 32 | ssdOff(); |
rmaalmeida | 1:083267bc0a0e | 33 | soWrite(value >> 4); |
rmaalmeida | 1:083267bc0a0e | 34 | // digitalWrite(LCD_RS_PIN, rs); |
rmaalmeida | 1:083267bc0a0e | 35 | LCD_RS_PIN = rs; |
rmaalmeida | 1:083267bc0a0e | 36 | pulseEnablePin(); |
rmaalmeida | 1:083267bc0a0e | 37 | |
rmaalmeida | 1:083267bc0a0e | 38 | soWrite(value & 0x0F); |
rmaalmeida | 1:083267bc0a0e | 39 | // digitalWrite(LCD_RS_PIN, rs); |
rmaalmeida | 1:083267bc0a0e | 40 | LCD_RS_PIN = rs; |
rmaalmeida | 1:083267bc0a0e | 41 | pulseEnablePin(); |
rmaalmeida | 1:083267bc0a0e | 42 | } |
rmaalmeida | 1:083267bc0a0e | 43 | void lcdCommand(char value) { |
rmaalmeida | 1:083267bc0a0e | 44 | pushByte(value, 0); |
rmaalmeida | 1:083267bc0a0e | 45 | wait_us(40); |
rmaalmeida | 1:083267bc0a0e | 46 | if((value==0x03)||(value==0x02)||(value==0x01)){ |
rmaalmeida | 1:083267bc0a0e | 47 | wait_ms(2); |
rmaalmeida | 1:083267bc0a0e | 48 | } |
rmaalmeida | 1:083267bc0a0e | 49 | } |
rmaalmeida | 1:083267bc0a0e | 50 | void lcdPosition(int line, int col) { |
rmaalmeida | 1:083267bc0a0e | 51 | if (line == 0) { |
rmaalmeida | 1:083267bc0a0e | 52 | lcdCommand(0x80 + (col % 16)); |
rmaalmeida | 1:083267bc0a0e | 53 | } |
rmaalmeida | 1:083267bc0a0e | 54 | if (line == 1) { |
rmaalmeida | 1:083267bc0a0e | 55 | lcdCommand(0xC0 + (col % 16)); |
rmaalmeida | 1:083267bc0a0e | 56 | } |
rmaalmeida | 1:083267bc0a0e | 57 | } |
rmaalmeida | 1:083267bc0a0e | 58 | void lcdChar(char value) { |
rmaalmeida | 1:083267bc0a0e | 59 | pushByte(value, 1); |
rmaalmeida | 1:083267bc0a0e | 60 | wait_us(80); |
rmaalmeida | 1:083267bc0a0e | 61 | } |
rmaalmeida | 1:083267bc0a0e | 62 | //Imprime um texto (vetor de char) |
rmaalmeida | 1:083267bc0a0e | 63 | void lcdString(char msg[]) { |
rmaalmeida | 1:083267bc0a0e | 64 | int i = 0; |
rmaalmeida | 1:083267bc0a0e | 65 | while (msg[i] != 0) { |
rmaalmeida | 1:083267bc0a0e | 66 | lcdChar(msg[i]); |
rmaalmeida | 1:083267bc0a0e | 67 | i++; |
rmaalmeida | 1:083267bc0a0e | 68 | } |
rmaalmeida | 1:083267bc0a0e | 69 | } |
rmaalmeida | 1:083267bc0a0e | 70 | void lcdNumber(int value) { |
rmaalmeida | 1:083267bc0a0e | 71 | int i = 10000; //M�ximo 99.999 |
rmaalmeida | 1:083267bc0a0e | 72 | while (i > 0) { |
rmaalmeida | 1:083267bc0a0e | 73 | lcdChar((value / i) % 10 + 48); |
rmaalmeida | 1:083267bc0a0e | 74 | i /= 10; |
rmaalmeida | 1:083267bc0a0e | 75 | } |
rmaalmeida | 1:083267bc0a0e | 76 | } |
rmaalmeida | 1:083267bc0a0e | 77 | // Rotina de incializa��o |
rmaalmeida | 1:083267bc0a0e | 78 | void lcdInit() { |
rmaalmeida | 1:083267bc0a0e | 79 | // pinMode(LCD_EN_PIN, OUTPUT); |
rmaalmeida | 1:083267bc0a0e | 80 | // pinMode(LCD_RS_PIN, OUTPUT); |
rmaalmeida | 1:083267bc0a0e | 81 | soInit(); |
rmaalmeida | 1:083267bc0a0e | 82 | ssdOff(); |
rmaalmeida | 1:083267bc0a0e | 83 | wait_ms(15); |
rmaalmeida | 1:083267bc0a0e | 84 | // Comunica��o come�a em estado incerto |
rmaalmeida | 1:083267bc0a0e | 85 | pushNibble(0x03, 0); |
rmaalmeida | 1:083267bc0a0e | 86 | wait_ms(5); |
rmaalmeida | 1:083267bc0a0e | 87 | pushNibble(0x03, 0); |
rmaalmeida | 1:083267bc0a0e | 88 | wait_us(160); |
rmaalmeida | 1:083267bc0a0e | 89 | pushNibble(0x03, 0); |
rmaalmeida | 1:083267bc0a0e | 90 | wait_us(160); |
rmaalmeida | 1:083267bc0a0e | 91 | // Mudando comunica��o para 4 bits |
rmaalmeida | 1:083267bc0a0e | 92 | pushNibble(0x02, 0); |
rmaalmeida | 1:083267bc0a0e | 93 | wait_ms(10); |
rmaalmeida | 1:083267bc0a0e | 94 | // Configura o display |
rmaalmeida | 1:083267bc0a0e | 95 | lcdCommand(0x28); //8bits, 2 linhas, fonte: 5x8 |
rmaalmeida | 1:083267bc0a0e | 96 | lcdCommand(0x08 + 0x04); //display on |
rmaalmeida | 1:083267bc0a0e | 97 | lcdCommand(0x01); //limpar display, voltar p/ posi��o 0 |
rmaalmeida | 1:083267bc0a0e | 98 | } |