Bom material em inglês para aprendizagem sobre microcontroladores com foco no PICMicro da Microchip, abordando com mais profundamente a programação assembly focada no famoso PIC16F84.
1) Digital Representation part 1
2) Digital Representation part 2
3) Logic Circuitry part 1
4) Logic Circuitry part 2
5) Logic Circuitry part 3
6) Logic Circuitry part 4
7) Stored Program Processing part 1
8) Stored Program Processing part 2
9) Stored Program Processing part 3
10) Stored Program Processing part 4
11) The PIC16f84 Microcontroller part 1
12) The PIC16f84 Microcontroller part 2
13) The PIC16f84 Microcontroller part 3
14) The Instruction Set part 1
15) The Instruction Set part 2
16) The Instruction Set part 3
17) The Instruction Set part 4
18) Subroutines and Modules part 1
19) Subroutines and Modules part 2
20) Subroutines and Modules part 3
21) Subroutines and Modules part 4
22) Interrupt Handling part 1
23) Interrupt Handling part 2
24) Interrupt Handling part 3
25) Assembly Language part 1
26) Assembly Language part 2
27) Assembly Language part 3
28) Assembly Language part 4
29) High Level Language part 1
30) High Level Language part 2
31) The Real World part 1
32) The Real World part 2
33) One Byte at a Time part 1
34) One Byte at a Time part 2
35) One Byte at a Time part 3
36) One Byte at a Time part 4
37) One Byte at a Time part 5
38) One Bit at a Time part 1
39) One Bit at a Time part 2
40) One Bit at a Time part 3
41) One Bit at a Time part 4
42) One Bit at a Time part 5
43) One Bit at a Time part 6
44) One Bit at a Time part 7
45) One Bit at a Time part 8
46) Time is of the Essence part 1
47) Time is of the Essence part 2
48) Time is of the Essence part 3
49) Time is of the Essence part 4
50) Take the Rough with the Smooth part 1
51) Take the Rough with the Smooth part 2
52) Take the Rough with the Smooth part 3
53) Take the Rough with the Smooth part 4
54) Take the Rough with the Smooth part 5
55) To Have and to Hold part 1
56) To Have and to Hold part 2
57) A Case Study part 1
58) A Case Study part 2
59) 14-bit Core Instruction Set
60) Special Purpose Register Structure for the PIC16C74B
61) C Instruction Set
62) Acronyms and Abbreviations
Fonte: what-when-how
In Depth Tutorials and Information
Mostrando postagens com marcador Microcontrolador: PIC. Mostrar todas as postagens
Mostrando postagens com marcador Microcontrolador: PIC. Mostrar todas as postagens
quarta-feira, 20 de junho de 2018
segunda-feira, 16 de março de 2015
Material sobre o PIC18 (Slides em inglês)
Material do prof. Orlando J. Hernandez, Ph.D., da cadeira de Eng, Elétrica e da Computação do The College of New Jersey.
| Chapter 1: Introduction to PIC18 | 22-Nov-2010 16:19 | 140K | ||
| Chapter 2: Assembly Language Programming | 22-Nov-2010 16:19 | 223K | ||
| Chapter 3: PIC18 Development Tools | 22-Nov-2010 16:19 | 288K | ||
| Chapter 7: Parallel Ports | 22-Nov-2010 16:19 | 263K | ||
| Chapter 8: Timers and CCP Modules | 22-Nov-2010 16:19 | 326K | ||
| Chapter 9: Universal Synchronous Asynchronous Receiver Transceiver | 22-Nov-2010 16:19 | 244K | ||
| Chapter 12: Analog-to-Digital Converter | 22-Nov-2010 16:19 | 273K |
quinta-feira, 12 de março de 2015
Curso básico Microcontrolador PIC (baseado no 16F84 e assembly)
Curso PIC
AULA 01: Mplab o que é, e como instalar no seu computador
AULA 02: Configurando o MPlab para usar o PIC16F84-A com um cristal oscilador de 4 Mhz
AULA 03: Primeiro Projeto - Um gerador de onda quadrada
AULA 04: Erros de Sintaxe no Código Fonte
AULA 05: Abrindo um projeto já existente
AULA 06: Usando a Simulação do MPlab
AULA 07: Considerações sobre o MPlab
AULA 08: Microcontroladores
AULA 09: Registros de Controle da CPU
AULA 10: Construindo um Gravador de PIC
AULA 11: Rotinas de Delay
AULA 12: Rotinas de Delay com Timer0
AULA 13: Rotinas de Delay Temporização (teoria e prática)
AULA 14: Fazendo um LED Piscar
AULA 15: Aplicação de entradas e saídas digitais
AULA 16:^Controlando um display de 7 segmentos
AULA 17: Uso das Interrupções e Sleep
AULA 18: Interrupção de RB0
AULA 19: Conhecendo o WatchDog
AULA 20: Estudando a EEPROM
AULA 21: Display LCD inteligente
Este trabalho foi desenvolvido em toda a sua parte pelo Professor Adilson Gutierres. O site Eletrônica 24h melhorou a sua navegação. De qualquer forma, qualquer dúvida sobre o conteúdo deve ser dirigida ao autor do curso. Este curso não será vendido, pois o trabalho pertence ao Professor Adilson Gutierres.
AULA 01: Mplab o que é, e como instalar no seu computador
AULA 02: Configurando o MPlab para usar o PIC16F84-A com um cristal oscilador de 4 Mhz
AULA 03: Primeiro Projeto - Um gerador de onda quadrada
AULA 04: Erros de Sintaxe no Código Fonte
AULA 05: Abrindo um projeto já existente
AULA 06: Usando a Simulação do MPlab
AULA 07: Considerações sobre o MPlab
AULA 08: Microcontroladores
AULA 09: Registros de Controle da CPU
AULA 10: Construindo um Gravador de PIC
AULA 11: Rotinas de Delay
AULA 12: Rotinas de Delay com Timer0
AULA 13: Rotinas de Delay Temporização (teoria e prática)
AULA 14: Fazendo um LED Piscar
AULA 15: Aplicação de entradas e saídas digitais
AULA 16:^Controlando um display de 7 segmentos
AULA 17: Uso das Interrupções e Sleep
AULA 18: Interrupção de RB0
AULA 19: Conhecendo o WatchDog
AULA 20: Estudando a EEPROM
AULA 21: Display LCD inteligente
quinta-feira, 30 de outubro de 2014
eBook online sobre o PIC16F877 abordando linguagem assembly (inglês)
Este livro é uma coleção de notas de aulas do Prof. Dr. Charles Kim, sobre programação em linguagem assembly com o PIC16F877 e suas aplicações em robôs autônomos, controladores de braços robóticos e outros projetos interessantes.
Capítulos em pdf:
1. Chapter 1: Introduction.
3. Chapter 3: Instructions Sets
4. Chapter 4: Coding Environment
5. Chapter 5: Serial Communication
6. Chapter 6: LCD Displaying and IR Remote Control Applications
7. Chapter 7: Motor Control and Robot Project
8. Chapter 8: A/D Conversion and Data Acquisition
9. Chapter 9: Timer Modules and Digital Clock Applications
10. Chapter 10: Synchronous Serial Communication and Keyboard Connections
11. Chapter 11: Voice Synthesizer Project
12.. Chapter 12: Internal EEPROM Access
13. Chapter 13: CCP Module and PWM
14. Chapter 14: SSP Module and I2C Bus for External EEPROM
15. Chapter 15: Armatron Control
16. Chapter 16: Digital Control using PC with IR
domingo, 22 de junho de 2014
Apostila sobre Microcontrolador PIC16F84
Apostila sobre microcontrolador PIC16F84, elaborada pelo prof. Getúlio Teruo Tateoki, Engenheiro e Professor das Engenharias do UniSalesiano-Araçatuba/SP.
Apostila sobre Microcontrolador PIC (PIC16F84)
Apostila elaborada pelo prof. Fábio Renato Elias Boaventura, aborda os conceitos básicos sobre microcontroladores, com foco no PIC16F84, explorando a programação assembly com o MPLab.
quarta-feira, 19 de março de 2014
Apostila Aplicações práticas com o SANUSB e programação C com o Compilador MPLabX
Esta apostila aborda aplicações práticas com microcontroladores PICMicro da família PIC18 da Microchip, Utilizando a plataforma de desenvolvimento SANUSB. Nesta apostila é abordado o uso do compilador C MPLabX C18.
Esta apostila foi elaborada pelos Profs. Sandro César Silveira Jucá, professor da área de telemática do IFCE, e Renata Imaculada Soares Pereira.
Postado por
Mecatrônica na Net
às
14:02
Nenhum comentário:
Enviar por e-mailPostar no blog!Compartilhar no XCompartilhar no FacebookCompartilhar com o Pinterest
Marcadores:
Aplicação com PIC,
Apostilas,
Compilador C para Microcontroladores,
Compilador MPLab XC,
Compilador para Microcontrolador,
Ling. C para PIC,
Microcontrolador,
Microcontrolador: PIC,
PICMicro
Apostila Aplicações práticas com o SANUSB e programação C com o Compilador CCS
Esta apostila aborda aplicações práticas com microcontroladores PICMicro da família PIC18 da Microchip, Utilizando a plataforma de desenvolvimento SANUSB. Esta apostila foi elaborada pelos Profs. Sandro César Silveira Jucá, professor da área de telemática do IFCE, e Renata Imaculada Soares Pereira.
Sumário
Postado por
Mecatrônica na Net
às
13:56
Nenhum comentário:
Enviar por e-mailPostar no blog!Compartilhar no XCompartilhar no FacebookCompartilhar com o Pinterest
Marcadores:
Aplicação com PIC,
Apostilas,
CCS,
CCS C,
Compilador C para Microcontroladores,
Ling. C para PIC,
Microcontrolador: PIC,
PICMicro
sábado, 1 de fevereiro de 2014
PIC Microcontrollers - Programming in C
Ebook on-line, disponibilizado para acesso gratuito pela MikroElektronika, aborda o básico de microcontroladores PIC, com foco na linguagem C e no PIC16F887.
Table of Contents
domingo, 20 de outubro de 2013
segunda-feira, 23 de setembro de 2013
Apostila MICROCONTROLADORES PIC PROGRAMAÇÃO EM LINGUAGEM C: PIC16F628A,16F876A, Compilador CCS C
Apostila sobre Microcontrolador PIC, abordando linguagem C com o compilador CCS C, focando nos modelos PIC16F628A,16F876A.
terça-feira, 6 de agosto de 2013
Apostila de Sistemas Embutidos com Microcontroladores PIC (SENAI/RS)
Deixo aqui, os links do material da disciplina de programação de microcontroladores PIC, abordando assembly e linguagem C embarcada, com uso do compilador CCS.
Parte 1 => INTRODUÇÃO A PROGRAMAÇÃO DE MICROCONTROLADORES : Uma breve introdução a programação de microcontroladores, conhecendo os principais aspectos da programação em baixo nível.
Parte 1 => INTRODUÇÃO A PROGRAMAÇÃO DE MICROCONTROLADORES : Uma breve introdução a programação de microcontroladores, conhecendo os principais aspectos da programação em baixo nível.
- Aula 1 - Considerações sobre a disciplina. Onde são usados os microcontroladores
- 1 - Perfil de um técnico em automação industrial - reflexão
- 2 - Uma breve abordagem sobre o uso de microcontroladores
- 3 - Exercícios de fixação
- 4 - Diferença entre CIRCUITO INTEGRADO, MICROPROCESSADOR e MICROCONTROLADOR
- Aula 2 - Microchip PIC16F877 e suas características. / Transferência de programas para um microcontrolador
- 1 - Conhecendo o microcontrolador PIC16F877
- 2 - Conhecendo a estação CUSCOPIC
- 3- Programas exemplos para transferir para o PIC (serão usados conforme instruções do tópico 4)
- 4 - Como transferir programas para o microcontrolador usando EPIC (via porta paralela)
- 5 – Como transferir programas para o microcontrolador usando bootloader (via porta serial)
- Aula 3 - Linguagem ASSEMBLY e suas aplicações. Exemplo de um programa assembly. Avaliação parcial.
Parte 2 => LINGUAGEM C : Uso de uma linguagem de mais alto nível para desenvolvimento de aplicações dedicadas, visando o reaproveitamento de código e a facilidade em utilizar os recursos do microcontrolador.
MATERIAL DE APOIO --> CARTÃO DE REFERÊNCIA DA LINGUAGEM C PADRÃO CCS <--
- Aula 4 - Ambientação. Uso do compilador C. Exemplos de programa em linguagem
- Linguagem COMPILADA ? O que é ?
- O compilador - Manual do CCS
- Exemplo de compilação 1
- Exercício de compilação 1
- Exercício de compilação 2 - complementar
- Exemplos de programas em linguagem C. Compile-os e execute na bancada PLCPIC.
- Pisca pisca de leds
- Exibe mensagem no display
- Usando o IF
- Contagem regressiva
- obs: Caso não consiga abrir os exemplos, clique AQUI para abrir todos os exemplos em um arquivo PDF.
- Aula 5 - Estrutura básica de um programa em linguagem C. Uso das chaves e do ponto e vírgula.
- 1) Para que serve e onde usar as chaves em C
- 2) Exercício prático 1 (para treinar sobre as chaves)
- 3) Onde deve ser usado o ponto e vírgula
- 4) Exercício prático 2 (para treinar o uso do ponto e vírgula)
- Aula 6 - Declaração de variáveis e tipos de dados
- Tipos de dados da Linguagem C
- - Exercício 1: Exemplo de um contador de peças
- - Exercício 2: Implementação
- Aula 7 - Funções de entrada e saída - entrada/saída digital e LCD. Uso da diretiva DEFINE.
- Aula 8 - Operadores
- Operadores
- Matéria expandida no material de apoio (operadores1.doc e operadores2.doc)
- Programa exemplo & Exercícios
- Aula 9 - Funções de entrada e saída - Entrada analógica e PWM
- Aula 10 - Estruturas condicionais (IF e SWITCH)
- Aula 11 - Estruturas de repetição (WHILE, DO/WHILE, FOR)
- Aula 12 - Funções e passagem de parâmetros (display 7 segmentos e teclado matricial na PLCPIC)
Parte 3 =>LINGUAGEM C : Prática e recursos avançados
- Aula 13 - Situação problema - Apresentação da tarefas, definição dos grupos e das propostas.
- SAPZ - Situação de aprendizagem
- Critérios de avaliação da SAPZ
- Considerações sobre avaliação das situações de aprendizagem
- Aula 14 - Situação problema - Modelo do programa e cronograma / Implementação.
- Aula 15 - Situação problema - Implementação.
- Aula 16 - Situação problema - Implementação / Testes / Avaliação.
- Aula 17 - Recursos avançados : Comunicação serial, EEPROM.
- Aula 18 - Recursos avançados. Breve abordagem sobre Matrizes e ponteiros. Interrupções, Timer/Counters e Alocação dinâmica de memória.
- Aula 19 - Ladder para microcontrolador.
- 1) Tutorial rápido LDMICRO
- 2) Tutorial completo LDMICRO
- 3) Exemplos de programas ladder para o LDMICRO
- 4) LDMICRO.exe
- Aula 20 - Exercícios / Avaliação.
Material de apoio
Programas exemplos em linguagem C
sexta-feira, 26 de julho de 2013
Microcontroladores PIC - Abordando a IDE MPLABX e o Compilador XC8
Vídeos Tutoriais sobre programação em C para microcontroladores PIC, Abordando a IDE MPLABX e o Compilador XC8. Estes vídeos foram produzidos por Ezequiel Donhauser
Clique nos links para assistir:
<Uma Geral - parte 1>  <Uma Geral - parte 2>  <Delays> <Arquivos de Código e Simulação AQUI>  <Display 16x2> <Arquivos de Código e Simulação AQUI>
Postado por
Mecatrônica na Net
às
15:24
Um comentário:
Enviar por e-mailPostar no blog!Compartilhar no XCompartilhar no FacebookCompartilhar com o Pinterest
Marcadores:
Aplicação com PIC,
Compilador C para Microcontroladores,
Compilador MPLab XC,
Ling. C para PIC,
Microcontrolador: PIC,
PIC,
PICMicro,
Tutorial,
Vídeo-Aulas,
Vídeos
sábado, 20 de julho de 2013
Driver do Display Gráfico Everbouquet MG1903A (192x32 com ST7920) para CCS C / PIC
Driver para o Display Everbouquet MG1903A (192x32 com ST7920)
#byte PORTA = 0xF80
#bit RA0 = PORTA.0
#bit RA1 = PORTA.1
#bit RA2 = PORTA.2
#bit RA3 = PORTA.3
#bit RA4 = PORTA.4
#bit RA5 = PORTA.5
#bit RA6 = PORTA.6
#bit RA7 = PORTA.7
#byte PORTB = 0xF81
#bit RB0 = PORTB.0
#bit RB1 = PORTB.1
#bit RB2 = PORTB.2
#bit RB3 = PORTB.3
#bit RB4 = PORTB.4
#bit RB5 = PORTB.5
#bit RB6 = PORTB.6
#bit RB7 = PORTB.7
#byte PORTC = 0xF82
#bit RC0 = PORTC.0
#bit RC1 = PORTC.1
#bit RC2 = PORTC.2
#bit RC3 = PORTC.3
#bit RC4 = PORTC.4
#bit RC5 = PORTC.5
#bit RC6 = PORTC.6
#bit RC7 = PORTC.7
#byte PORTE = 0xF84
#bit RE3 = PORTE.3
/////////////////////////////////////////////////////////////////////////
//// mg1903a.h ////
//// ////
//// This file contains drivers for using a Everbouquet MG1903A with ////
//// a ST7920 display controller. The MG1903A is 192 by 32 pixels. ////
//// The driver treats the upper left pixel as (0,0). ////
//// ////
/////////////////////////////////////////////////////////////////////////
//// ////
//// LCD Pin connections: ////
//// * 1: VSS is connected to GND ////
//// * 2: VDD is connected to +5V ////
//// * 3: V0 - LCD operating voltage (Constrast adjustment) ////
//// * 4: R/S - Data or Instruction is connected to C7 ////
//// * 5: R/W - Read or Write is connected to C6 ////
//// * 6: Enable is connected to C5 ////
//// * 7-14: Data Bus 0 to 7 is connected to port B ////
//// * 15: Positive voltage for LED backlight is connected to +5V ////
//// * 16: Negavtive voltage for LED backlight is connected to GND ////
//// ////
/////////////////////////////////////////////////////////////////////////
//// ////
//// glcd_init () ////
//// * Must be called before any other function. ////
//// ////
//// glcd_pixel (x,y,color) ////
//// * Sets the pixel to the given color. ////
//// - color can be ON or OFF ////
//// ////
//// glcd_fillScreen (color) ////
//// * Fills the entire LCD with the given color. ////
//// - color can be ON or OFF ////
//// ////
/////////////////////////////////////////////////////////////////////////
#define GLCD_RS RC7 // Display Data / Control Data.
#define GLCD_RW RC6 // Read / Write
#define GLCD_E RC5 // Enable Signal.
#define GLCD_WIDTH 192
#define RS_FUNCTION 0
#define RS_DATA 1
#define RW_WRITE 0
#define RW_READ 1
#define TRIS_READ 0xFF
#define TRIS_WRITE 0x00
// Valores de color:
#define ON 1
#define OFF 0
typedef union
{
int16 word;
BYTE byte[2];
} Dots;
typedef struct
{
BOOLEAN refrescar;
Dots dots[32][12]; // Diemensiones máximas del display (x,y) = (191,31).
} GDRAM; // El punto (0,0) corresponde a la esquina superior izquierda.
GDRAM gdram;
/*-----------------------------------------------------------------------------------------
* Nombre: glcd_readByte
*
* Propósito: Reads a byte of data from the LCD.
*
* In/Out:
*
* Return: A byte of data read from the LCD.
*
* Requisitos:
*
* Descripción:
*----------------------------------------------------------------------------------------*/
BYTE glcd_readByte (BYTE address)
{
BYTE data; // Stores the data read from the LCD
set_tris_b (TRIS_READ); // Set PORTB to input
GLCD_RS = address;
delay_cycles(1);
GLCD_RW = RW_READ; // Set for reading
delay_cycles (1);
GLCD_E = 1; // Pulse the enable pin
delay_cycles (1);
data = PORTB; // Get the data from the display's output register
GLCD_E = 0;
return data;
}
/*------------------------------------------------------------------------------------------
* Nombre: glcd_writeByte
*
* Propósito: Write a byte of data to the LCD.
*
* In/Out:
*
* Return:
* - data (in): the byte of data to write.
*
* Requisitos:
*
* Descripción:
*
*----------------------------------------------------------------------------------------*/
void glcd_writeByte (BYTE address, BYTE data)
{
GLCD_RS = RS_FUNCTION;
while ( bit_test (glcd_readByte(RS_FUNCTION), 7) ) ; // Whait Busy Flag = FALSE!
set_tris_b (TRIS_WRITE); // Set PORTB to output
GLCD_RS = address;
delay_cycles(1);
GLCD_RW = RW_WRITE; // Set for writing
delay_cycles(1);
GLCD_E = 0;
PORTB = data; // Put the data on the port
delay_cycles (1);
GLCD_E = 1; // Pulse the enable pin
delay_cycles(5);
GLCD_E = 0;
}
/*------------------------------------------------------------------------------------------
* Nombre: glcd_fillScreen
*
* Propósito: Fill the LCD screen with the passed in color.
*
* In/Out:
* - color (in):
* ON - turn all the pixels on.
* OFF - turn all the pixels off.
*
* Return:
*
* Requisitos:
*
* Descripción: Sólo trabaja sobre la caché del display.
*
*----------------------------------------------------------------------------------------*/
void glcd_fillScreen (BYTE color)
{
int8 v, h;
int16 d;
d = (color == ON ? 0xFFFFL : 0x0000L);
for (v=0; v<32; v++)
{
for (h=0; h<12; h++)
{
gdram.dots[v][h].word = d;
}
}
gdram.refrescar = TRUE;
}
/*------------------------------------------------------------------------------------------
* Nombre: glcd_update
*
* Propósito: Update the LCD with data from the display cache.
*
* In/Out:
*
* Return:
*
* Requisitos:
*
* Descripción:
*----------------------------------------------------------------------------------------*/
void glcd_update ()
{
int8 v, h;
if (gdram.refrescar)
{
for (v=0; v<32; v++)
{
glcd_writeByte (RS_FUNCTION, 0x80 | v); // Set Vertical Address.
glcd_writeByte (RS_FUNCTION, 0x80 | 0); // Set Horizontal Address.
for (h=0; h<12; h++)
{
glcd_writeByte (RS_DATA, gdram.dots[v][h].byte[1]); // Write High Byte.
glcd_writeByte (RS_DATA, gdram.dots[v][h].byte[0]); // Write Low Byte.
}
}
gdram.refrescar = FALSE;
}
}
/*------------------------------------------------------------------------------------------
* Nombre: glcd_init
*
* Propósito: Inicialza el LCD.
*
* In/Out:
* - mode (in): OFF/ON - Turns the LCD off/on.
*
* Return:
*
* Requisitos: Call before using any other LCD function.
*
* Descripción:
*----------------------------------------------------------------------------------------*/
void glcd_init ()
{
set_tris_b (TRIS_WRITE); // PORTB as output.
GLCD_RS = RS_FUNCTION;
GLCD_RW = RW_WRITE;
GLCD_E = 0;
delay_ms (40);
glcd_writeByte (RS_FUNCTION, 0x30); // Specify 8 bit interface and basic instruction set.
delay_us (100);
glcd_writeByte (RS_FUNCTION, 0x30); // Specify 8 bit interface and basic instruction set.
delay_us (37);
glcd_writeByte (RS_FUNCTION, 0x0C); // Specify Display on, Cursor off and Blink off.
delay_us (100);
glcd_writeByte (RS_FUNCTION, 0x01); // Display clear.
delay_ms (10);
glcd_writeByte (RS_FUNCTION, 0x06); // AC Increase (cursor move right), don't shift the display.
delay_us (72);
glcd_writeByte (RS_FUNCTION, 0x34); // Select extended instruction set.
delay_us (72);
glcd_writeByte (RS_FUNCTION, 0x36); // Graphic display ON.
glcd_fillScreen (OFF);
glcd_update ();
}
/*------------------------------------------------------------------------------------------
* Nombre:
*
* Propósito: Turn a pixel on a graphic LCD on or off.
*
* In/Out:
* - x (in): the x coordinate of the pixel.
* - y (in): y - the y coordinate of the pixel.
* - color (in): ON or OFF.
*
* Return:
*
* Requisitos:
*
* Descripción:
*----------------------------------------------------------------------------------------*/
void glcd_pixel(int8 x, int8 y, int1 color)
{
int8 v, h, b;
v = y;
h = x/16;
b = 15 - (x%16);
// Modify the actual word.
if (color == ON) bit_set (gdram.dots[v][h].word, b);
else bit_clear (gdram.dots[v][h].word, b);
gdram.refrescar = TRUE;
}
#byte PORTA = 0xF80
#bit RA0 = PORTA.0
#bit RA1 = PORTA.1
#bit RA2 = PORTA.2
#bit RA3 = PORTA.3
#bit RA4 = PORTA.4
#bit RA5 = PORTA.5
#bit RA6 = PORTA.6
#bit RA7 = PORTA.7
#byte PORTB = 0xF81
#bit RB0 = PORTB.0
#bit RB1 = PORTB.1
#bit RB2 = PORTB.2
#bit RB3 = PORTB.3
#bit RB4 = PORTB.4
#bit RB5 = PORTB.5
#bit RB6 = PORTB.6
#bit RB7 = PORTB.7
#byte PORTC = 0xF82
#bit RC0 = PORTC.0
#bit RC1 = PORTC.1
#bit RC2 = PORTC.2
#bit RC3 = PORTC.3
#bit RC4 = PORTC.4
#bit RC5 = PORTC.5
#bit RC6 = PORTC.6
#bit RC7 = PORTC.7
#byte PORTE = 0xF84
#bit RE3 = PORTE.3
/////////////////////////////////////////////////////////////////////////
//// mg1903a.h ////
//// ////
//// This file contains drivers for using a Everbouquet MG1903A with ////
//// a ST7920 display controller. The MG1903A is 192 by 32 pixels. ////
//// The driver treats the upper left pixel as (0,0). ////
//// ////
/////////////////////////////////////////////////////////////////////////
//// ////
//// LCD Pin connections: ////
//// * 1: VSS is connected to GND ////
//// * 2: VDD is connected to +5V ////
//// * 3: V0 - LCD operating voltage (Constrast adjustment) ////
//// * 4: R/S - Data or Instruction is connected to C7 ////
//// * 5: R/W - Read or Write is connected to C6 ////
//// * 6: Enable is connected to C5 ////
//// * 7-14: Data Bus 0 to 7 is connected to port B ////
//// * 15: Positive voltage for LED backlight is connected to +5V ////
//// * 16: Negavtive voltage for LED backlight is connected to GND ////
//// ////
/////////////////////////////////////////////////////////////////////////
//// ////
//// glcd_init () ////
//// * Must be called before any other function. ////
//// ////
//// glcd_pixel (x,y,color) ////
//// * Sets the pixel to the given color. ////
//// - color can be ON or OFF ////
//// ////
//// glcd_fillScreen (color) ////
//// * Fills the entire LCD with the given color. ////
//// - color can be ON or OFF ////
//// ////
/////////////////////////////////////////////////////////////////////////
#define GLCD_RS RC7 // Display Data / Control Data.
#define GLCD_RW RC6 // Read / Write
#define GLCD_E RC5 // Enable Signal.
#define GLCD_WIDTH 192
#define RS_FUNCTION 0
#define RS_DATA 1
#define RW_WRITE 0
#define RW_READ 1
#define TRIS_READ 0xFF
#define TRIS_WRITE 0x00
// Valores de color:
#define ON 1
#define OFF 0
typedef union
{
int16 word;
BYTE byte[2];
} Dots;
typedef struct
{
BOOLEAN refrescar;
Dots dots[32][12]; // Diemensiones máximas del display (x,y) = (191,31).
} GDRAM; // El punto (0,0) corresponde a la esquina superior izquierda.
GDRAM gdram;
/*-----------------------------------------------------------------------------------------
* Nombre: glcd_readByte
*
* Propósito: Reads a byte of data from the LCD.
*
* In/Out:
*
* Return: A byte of data read from the LCD.
*
* Requisitos:
*
* Descripción:
*----------------------------------------------------------------------------------------*/
BYTE glcd_readByte (BYTE address)
{
BYTE data; // Stores the data read from the LCD
set_tris_b (TRIS_READ); // Set PORTB to input
GLCD_RS = address;
delay_cycles(1);
GLCD_RW = RW_READ; // Set for reading
delay_cycles (1);
GLCD_E = 1; // Pulse the enable pin
delay_cycles (1);
data = PORTB; // Get the data from the display's output register
GLCD_E = 0;
return data;
}
/*------------------------------------------------------------------------------------------
* Nombre: glcd_writeByte
*
* Propósito: Write a byte of data to the LCD.
*
* In/Out:
*
* Return:
* - data (in): the byte of data to write.
*
* Requisitos:
*
* Descripción:
*
*----------------------------------------------------------------------------------------*/
void glcd_writeByte (BYTE address, BYTE data)
{
GLCD_RS = RS_FUNCTION;
while ( bit_test (glcd_readByte(RS_FUNCTION), 7) ) ; // Whait Busy Flag = FALSE!
set_tris_b (TRIS_WRITE); // Set PORTB to output
GLCD_RS = address;
delay_cycles(1);
GLCD_RW = RW_WRITE; // Set for writing
delay_cycles(1);
GLCD_E = 0;
PORTB = data; // Put the data on the port
delay_cycles (1);
GLCD_E = 1; // Pulse the enable pin
delay_cycles(5);
GLCD_E = 0;
}
/*------------------------------------------------------------------------------------------
* Nombre: glcd_fillScreen
*
* Propósito: Fill the LCD screen with the passed in color.
*
* In/Out:
* - color (in):
* ON - turn all the pixels on.
* OFF - turn all the pixels off.
*
* Return:
*
* Requisitos:
*
* Descripción: Sólo trabaja sobre la caché del display.
*
*----------------------------------------------------------------------------------------*/
void glcd_fillScreen (BYTE color)
{
int8 v, h;
int16 d;
d = (color == ON ? 0xFFFFL : 0x0000L);
for (v=0; v<32; v++)
{
for (h=0; h<12; h++)
{
gdram.dots[v][h].word = d;
}
}
gdram.refrescar = TRUE;
}
/*------------------------------------------------------------------------------------------
* Nombre: glcd_update
*
* Propósito: Update the LCD with data from the display cache.
*
* In/Out:
*
* Return:
*
* Requisitos:
*
* Descripción:
*----------------------------------------------------------------------------------------*/
void glcd_update ()
{
int8 v, h;
if (gdram.refrescar)
{
for (v=0; v<32; v++)
{
glcd_writeByte (RS_FUNCTION, 0x80 | v); // Set Vertical Address.
glcd_writeByte (RS_FUNCTION, 0x80 | 0); // Set Horizontal Address.
for (h=0; h<12; h++)
{
glcd_writeByte (RS_DATA, gdram.dots[v][h].byte[1]); // Write High Byte.
glcd_writeByte (RS_DATA, gdram.dots[v][h].byte[0]); // Write Low Byte.
}
}
gdram.refrescar = FALSE;
}
}
/*------------------------------------------------------------------------------------------
* Nombre: glcd_init
*
* Propósito: Inicialza el LCD.
*
* In/Out:
* - mode (in): OFF/ON - Turns the LCD off/on.
*
* Return:
*
* Requisitos: Call before using any other LCD function.
*
* Descripción:
*----------------------------------------------------------------------------------------*/
void glcd_init ()
{
set_tris_b (TRIS_WRITE); // PORTB as output.
GLCD_RS = RS_FUNCTION;
GLCD_RW = RW_WRITE;
GLCD_E = 0;
delay_ms (40);
glcd_writeByte (RS_FUNCTION, 0x30); // Specify 8 bit interface and basic instruction set.
delay_us (100);
glcd_writeByte (RS_FUNCTION, 0x30); // Specify 8 bit interface and basic instruction set.
delay_us (37);
glcd_writeByte (RS_FUNCTION, 0x0C); // Specify Display on, Cursor off and Blink off.
delay_us (100);
glcd_writeByte (RS_FUNCTION, 0x01); // Display clear.
delay_ms (10);
glcd_writeByte (RS_FUNCTION, 0x06); // AC Increase (cursor move right), don't shift the display.
delay_us (72);
glcd_writeByte (RS_FUNCTION, 0x34); // Select extended instruction set.
delay_us (72);
glcd_writeByte (RS_FUNCTION, 0x36); // Graphic display ON.
glcd_fillScreen (OFF);
glcd_update ();
}
/*------------------------------------------------------------------------------------------
* Nombre:
*
* Propósito: Turn a pixel on a graphic LCD on or off.
*
* In/Out:
* - x (in): the x coordinate of the pixel.
* - y (in): y - the y coordinate of the pixel.
* - color (in): ON or OFF.
*
* Return:
*
* Requisitos:
*
* Descripción:
*----------------------------------------------------------------------------------------*/
void glcd_pixel(int8 x, int8 y, int1 color)
{
int8 v, h, b;
v = y;
h = x/16;
b = 15 - (x%16);
// Modify the actual word.
if (color == ON) bit_set (gdram.dots[v][h].word, b);
else bit_clear (gdram.dots[v][h].word, b);
gdram.refrescar = TRUE;
}
main example
#include "mg1903a.h"
#include "graphics.h"
#include <math.h>
#pragma zero_ram
void main()
{
int1 warn = FALSE;
int16 adc = 0L, adc_old = 0L;
char voltText[] = "Volts", warning[] = "Warning", W[] = "W";
float theta = 0;
inicializarMicro (); // Inicializa los registros de configuración del MCU y perifericos.
inicializarSD (); // Inicializa las estructuras de datos utilizadas por el programa.
activarSalidas (); // Inicializar las salidas.
glcd_rect(1, 5, 126, 15, NO, ON); // Outline the bar
glcd_text57(30, 18, voltText, 1, ON); // Display "Volts"
glcd_circle(145, 16, 10, NO, ON); // Draw the clock circle
while (TRUE)
{
adc = entradaAnalogica.valor; // Read a value from the ADC
displayVoltage (adc); // Display the reading
adc = (adc > 249L) ? 249L : adc; // Keep the value 249 or less
if(adc != adc_old)
{
glcd_rect (adc/2+1, 6, adc_old/2+1, 14, YES, OFF); // Clears the old bar
glcd_rect (1, 6, adc/2+1, 14, YES, ON); // Draws a new bar
adc_old = adc; // Set old value to new
if (adc > 200 && !warn) // Check if over 4 volts.
{
glcd_rect (68, 20, 110, 28, YES, ON); // Draw a filled black rectangle
glcd_text57 (70, 21, warning, 1, OFF); // Write "Warning" on the LCD
glcd_text57 (165, 10, W, 2, ON); // Escribir una W con el doble de tamaño.
warn = TRUE;
}
else if (adc <= 200 && warn)
{
glcd_rect (68, 20, 110, 28, YES, OFF); // Draw a filled white rectangle
glcd_rect (165, 10, 180, 28, YES, OFF); // Draw a filled white rectangle
warn = FALSE;
}
}
// The following 3 lines make the clock hand spin around
glcd_line (145, 16, 145+(int)(8*sin(theta)+.5), 16-(int)(8*cos(theta)+.5), OFF);
theta = (theta > 5.9) ? 0 : (theta += .3);
glcd_line (145, 16, 145+(int)(8*sin(theta)+.5), 16-(int)(8*cos(theta)+.5), ON);
glcd_update ();
// delay_ms(100); // Reduces flicker by allowing pixels to be on much longer than off.
}
}
Fonte: http://www.ccsinfo.com/forum/viewtopic.php?t=32819&highlight=st7920
#include "graphics.h"
#include <math.h>
#pragma zero_ram
void main()
{
int1 warn = FALSE;
int16 adc = 0L, adc_old = 0L;
char voltText[] = "Volts", warning[] = "Warning", W[] = "W";
float theta = 0;
inicializarMicro (); // Inicializa los registros de configuración del MCU y perifericos.
inicializarSD (); // Inicializa las estructuras de datos utilizadas por el programa.
activarSalidas (); // Inicializar las salidas.
glcd_rect(1, 5, 126, 15, NO, ON); // Outline the bar
glcd_text57(30, 18, voltText, 1, ON); // Display "Volts"
glcd_circle(145, 16, 10, NO, ON); // Draw the clock circle
while (TRUE)
{
adc = entradaAnalogica.valor; // Read a value from the ADC
displayVoltage (adc); // Display the reading
adc = (adc > 249L) ? 249L : adc; // Keep the value 249 or less
if(adc != adc_old)
{
glcd_rect (adc/2+1, 6, adc_old/2+1, 14, YES, OFF); // Clears the old bar
glcd_rect (1, 6, adc/2+1, 14, YES, ON); // Draws a new bar
adc_old = adc; // Set old value to new
if (adc > 200 && !warn) // Check if over 4 volts.
{
glcd_rect (68, 20, 110, 28, YES, ON); // Draw a filled black rectangle
glcd_text57 (70, 21, warning, 1, OFF); // Write "Warning" on the LCD
glcd_text57 (165, 10, W, 2, ON); // Escribir una W con el doble de tamaño.
warn = TRUE;
}
else if (adc <= 200 && warn)
{
glcd_rect (68, 20, 110, 28, YES, OFF); // Draw a filled white rectangle
glcd_rect (165, 10, 180, 28, YES, OFF); // Draw a filled white rectangle
warn = FALSE;
}
}
// The following 3 lines make the clock hand spin around
glcd_line (145, 16, 145+(int)(8*sin(theta)+.5), 16-(int)(8*cos(theta)+.5), OFF);
theta = (theta > 5.9) ? 0 : (theta += .3);
glcd_line (145, 16, 145+(int)(8*sin(theta)+.5), 16-(int)(8*cos(theta)+.5), ON);
glcd_update ();
// delay_ms(100); // Reduces flicker by allowing pixels to be on much longer than off.
}
}
Fonte: http://www.ccsinfo.com/forum/viewtopic.php?t=32819&highlight=st7920
Assinar:
Postagens (Atom)







