git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@219 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2008-03-07 15:24:00 +00:00
parent 959e29936f
commit d3ff29c189
10 changed files with 183 additions and 20 deletions

View File

@ -87,7 +87,7 @@ SRC = ../../ports/AVR/chcore.c ../../ports/AVR/avr_serial.c \
../../src/chserial.c \
../../src/lib/evtimer.c \
../../test/test.c \
board.c main.c
board.c lcd.c main.c
# List C++ source files here. (C dependencies are automatically generated.)

View File

@ -38,22 +38,22 @@
#define VAL_PORTB 0xFF
/* D7 D6 D5 D4 PC3 E R/W RS
* IN IN IN IN IN OUT OUT OUT
* DDRC 0 0 0 0 0 1 1 1
* OUT OUT OUT OUT IN OUT OUT OUT
* DDRC 1 1 1 1 0 1 1 1
* PU PU PU PU PU VAL VAL VAL
* PORTC 1 1 1 1 1 0 0 0
* PORTC 0 0 0 0 1 0 0 0
*/
#define VAL_DDRC 0x03
#define VAL_PORTC 0xF8
#define VAL_DDRC 0xF7
#define VAL_PORTC 0x08
/* PD7 PD6 PD5 PD4 TXD RXD PD1 PD0
* IN IN IN IN OUT IN IN IN
* DDRD 0 0 0 0 1 0 0 0
* PU PU PU PU VAL HiZ HiZ HiZ
* PORTD 1 1 1 1 1 0 0 0
* PU PU PU PU VAL HiZ PU PU
* PORTD 1 1 1 1 1 0 1 1
*/
#define VAL_DDRD 0x08
#define VAL_PORTD 0xF8
#define VAL_PORTD 0xFB
/* PE7 PE6 BZ2 BZ2 PE3 PE2 PE1 PE0
* IN IN OUT OUT IN IN OUT IN
@ -67,12 +67,12 @@
/* TDI TDO TMS TCK PF3 PF2 PF1 PF0
* x x x x IN IN IN IN
* DDRF 0 0 0 0 0 0 0 0
* PU PU PU PU PU PU PU PU
* PORTF 1 1 1 1 1 1 1 1
* x x x x PU PU PU PU
* PORTF 0 0 0 0 1 1 1 1
*
*/
#define VAL_DDRF 0x00
#define VAL_PORTF 0xFF
#define VAL_PORTF 0x0F
/* x x x x x PG2 PG1 PG0
* x x x x x IN IN IN
@ -99,6 +99,8 @@
#define PORTC_44780_D5 (1 << 5)
#define PORTC_44780_D6 (1 << 6)
#define PORTC_44780_D7 (1 << 7)
#define PORTC_44780_DATA (PORTC_44780_D4 | PORTC_44780_D5 | \
PORTC_44780_D6 | PORTC_44780_D7)
#define PORTE_BUZZ1 (1 << 4)
#define PORTE_BUZZ2 (1 << 5)

View File

@ -0,0 +1,97 @@
/*
ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ch.h>
#include <avr/io.h>
#include "board.h"
#include "lcd.h"
static void e_pulse(void) {
volatile uint8_t i;
PORTC |= PORTC_44780_E;
for (i = 0; i < ELOOPVALUE; i++);
;
PORTC &= ~PORTC_44780_E;
}
static void wait_not_busy(void) {
chThdSleep(2);
}
/*
* 44780 soft reset procedure.
*/
void lcdInit(void) {
PORTC = (PORTC & ~(PORTC_44780_DATA | PORTC_44780_RS | PORTC_44780_E | PORTC_44780_RW)) |
(LCD_CMD_INIT8 & PORTC_44780_DATA);
chThdSleep(50);
e_pulse();
chThdSleep(10);
e_pulse();
chThdSleep(2);
e_pulse();
wait_not_busy();
PORTC = (PORTC & ~(PORTC_44780_DATA | PORTC_44780_RS | PORTC_44780_E | PORTC_44780_RW)) |
(LCD_CMD_INIT4 & PORTC_44780_DATA);
e_pulse();
lcdCmd(LCD_CMD_INIT4);
lcdCmd(LCD_SET_DM | LCD_DM_DISPLAY_ON);
lcdCmd(LCD_SET_INCREMENT_MODE);
}
/*
* Sends a command byte to the 44780.
*/
void lcdCmd(uint8_t cmd) {
wait_not_busy();
PORTC = (PORTC | PORTC_44780_DATA) & (cmd | (0x0F & ~PORTC_44780_RS));
e_pulse();
PORTC = (PORTC | PORTC_44780_DATA) & ((cmd << 4) | (0x0F & ~PORTC_44780_RS));
e_pulse();
}
/*
* Writes a char on the LCD at the current position.
*/
void lcdPutc(char c) {
uint8_t b;
wait_not_busy();
b = c | 0x0F;
PORTC = (PORTC | PORTC_44780_DATA | PORTC_44780_RS) & (c | 0x0F);
e_pulse();
PORTC = (PORTC | PORTC_44780_DATA | PORTC_44780_RS) & ((c << 4) | 0x0F);
e_pulse();
}
/*
* Writes a string on the LCD at an absolute address.
*/
void lcdPuts(uint8_t pos, char *p) {
lcdCmd(LCD_SET_DDRAM_ADDRESS | pos);
while (*p)
lcdPutc(*p++);
}

View File

@ -0,0 +1,52 @@
/*
ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _LCD_H_
#define _LCD_H_
#define ELOOPVALUE 10
#define LCD_CLEAR 0x01
#define LCD_RETURN_HOME 0x02
#define LCD_SET_INCREMENT_MODE 0x06
#define LCD_SET_DM 0x08
#define LCD_DM_DISPLAY_ON 4
#define LCD_DM_DISPLAY_OFF 0
#define LCD_DM_CURSOR_ON 2
#define LCD_DM_CURSOR_OFF 0
#define LCD_DM_BLINK_ON 1
#define LCD_DM_BLINK_OFF 0
#define LCD_CMD_INIT4 0x28
#define LCD_CMD_INIT8 0x38
#define LCD_SET_DDRAM_ADDRESS 0x80
#define LCD_LINE1 0
#define LCD_LINE2 40
void lcdInit(void);
void lcdCmd(uint8_t cmd);
void lcdPutc(char c);
void lcdPuts(uint8_t pos, char *p);
#endif /* _LCD_H_ */

View File

@ -24,6 +24,7 @@
#include <avr/io.h>
#include "board.h"
#include "lcd.h"
void hwinit(void);
@ -31,7 +32,8 @@ static WorkingArea(waThread1, 32);
static msg_t Thread1(void *arg) {
while (TRUE) {
PORTA ^= PORTA_RELAY;
if (!(PINA & PORTA_BUTTON2))
PORTA ^= PORTA_RELAY;
chThdSleep(1000);
}
return 0;
@ -40,7 +42,7 @@ static msg_t Thread1(void *arg) {
static void TimerHandler(eventid_t id) {
msg_t TestThread(void *p);
if (!(PORTA & PORTA_BUTTON1))
if (!(PINA & PORTA_BUTTON1))
TestThread(&SER2);
}
@ -59,6 +61,15 @@ int main(int argc, char **argv) {
*/
chSysInit();
/*
* This initialization requires the OS already active because it uses delay
* APIs inside.
*/
lcdInit();
lcdCmd(LCD_CLEAR);
lcdPuts(LCD_LINE1, " ChibiOS/RT ");
lcdPuts(LCD_LINE2, " Hello World! ");
/*
* Event Timer initialization.
*/

View File

@ -8,8 +8,8 @@ The demo runs on an Olimex AVR-MT-128 board.
** The Demo **
The demo currently just toggles the relay using a thread. It will be expanded
in next releases.
The demo currently just writes a hello world on the LCD and toggles the relay
using a thread while button 2 is pressed.
By pressing the button 1 the test suite is activated, output on serial port 2.
** Build Procedure **

View File

@ -4,7 +4,7 @@
# Project related configuration options
#---------------------------------------------------------------------------
PROJECT_NAME = ChibiOS/RT
PROJECT_NUMBER = "0.5.5 beta"
PROJECT_NUMBER = "0.6.0 beta"
OUTPUT_DIRECTORY = .
CREATE_SUBDIRS = NO
OUTPUT_LANGUAGE = English

View File

@ -13,7 +13,7 @@ Homepage</h2>
</tr>
<tr>
<td style="text-align: center; vertical-align: top; width: 150px;">Current
Version 0.5.5<br>
Version 0.6.0<br>
-<br>
<a href="http://sourceforge.net/projects/chibios/" rel="me" target="_top">Project on SourceForge</a><br>
<a href="html/index.html" target="_top" rel="me">Documentation</a><br>

View File

@ -150,11 +150,11 @@ void InitSerial(void) {
#ifdef USE_AVR_USART0
/* I/O queues setup.*/
chFDDInit(&SER1, ib1, sizeof ib1, NULL, ob1, sizeof ob1, OutNotify1);
SetUSART0I(UBRR(38400), 0);
SetUSART0I(UBRR(38400), (1 << UCSZ1) | (1 << UCSZ0));
#endif
#ifdef USE_AVR_USART1
chFDDInit(&SER2, ib2, sizeof ib2, NULL, ob2, sizeof ob2, OutNotify2);
SetUSART1I(UBRR(38400), 0);
SetUSART1I(UBRR(38400), (1 << UCSZ1) | (1 << UCSZ0));
#endif
}

View File

@ -74,6 +74,7 @@ AVR-AT90CANx-GCC - Port on AVR AT90CAN128, not tested on hardware yet.
it, the changes were required because the type names were a concern for
some users.
- Implemented a serial driver in the AVR port.
- Implemented a simple HD44780 LCD driver into the AVRmega128 demo.
- Reworked the AVR AT90CAN128 port to share the common AVR code.
- Modified the test suite to be compatible with 8 bit micros.
- MSVC demo dropped, it is still possible to use the MinGW demo as simulator