|
|
Elektronika.lt portalo forumas
Jūs esate neprisijungęs lankytojas. Norint dalyvauti diskusijose, būtina užsiregistruoti ir prisijungti prie forumo.
Prisijungę galėsite kurti naujas temas, atsakyti į kitų užduotus klausimus, balsuoti forumo apklausose.
Administracija pasilieka teisę pašalinti pasisakymus bei dalyvius,
kurie nesilaiko forumo taisyklių.
Pastebėjus nusižengimus, prašome pranešti.
Dabar yra 2025 01 20, 10:33. Visos datos yra GMT + 2 valandos.
|
|
|
|
Forumas » Elektronika žaliems » attiny2313 ir 16x1 lcd
|
Jūs negalite rašyti naujų pranešimų į šį forumą Jūs negalite atsakinėti į pranešimus šiame forume Jūs negalite redaguoti savo pranešimų šiame forume Jūs negalite ištrinti savo pranešimų šiame forume Jūs negalite dalyvauti apklausose šiame forume
|
|
|
|
attiny2313 ir 16x1 lcd |
Parašytas: 2010 11 01, 12:42 |
|
|
|
Sveiki gal zinot kur rasti pamoku kaip su siuo mikrovaldikliu galima butu isgauti vaizda tokiame lcd? reiktu jog info butu nuo visisko 0- kitaip sakant primytiviausas c kodas, kuri galima butu po biski tobulinti, o ne taip kaip dazniausiai googlei matosi: clock timer, kalendoriai, i6 kurio tokiam kiap man sunku kazka padaryti . Na gal supratot ko man reikia |
|
|
|
|
|
attiny2313 ir 16x1 lcd |
Parašytas: 2010 11 01, 18:37 |
|
|
|
tai kad man ir taip ir anaip nesukompiliuoja is ten viska parsisunciau kazkokias klaidas randa 5 error ir 1 warning lygtais |
|
|
|
|
|
attiny2313 ir 16x1 lcd |
Parašytas: 2010 11 01, 21:35 |
|
|
|
Dar reikia ten lcd.h faile nustatyti ant kuriu portu ten ta lcd jungsi |
|
|
|
|
|
attiny2313 ir 16x1 lcd |
Parašytas: 2010 11 02, 07:46 |
|
|
|
zinau biblioteka lcd.h kozkokia is m raides ir lcd.c ikeliau kur reikia ir istaisiau ten tuos portus is c i b ir ten tuos kitus vis vien nieko. nete radau kitoki kazkokiu sudetingesniu kodu, su anuo viskas ok, bet aisku geriau butu jei su siuo viskas gautusi, nes su siuo kaip matau paprasciau nei su anuo |
|
|
|
|
|
|
attiny2313 ir 16x1 lcd |
Parašytas: 2010 11 07, 13:50 |
|
|
|
gal zinot kame reikalas jog mano 16x1 lcd padalina i dvi dalis po astuonis simbolius? gal galit pasakyti kur man cia ka taisyti reikia?
LCD.C
Kodas: |
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "lcd_lib.h"
//Strings stored in AVR Flash memory
const uint8_t welcomeln1[] PROGMEM="AVR LCD DEMO\0";
const uint8_t curhome[] PROGMEM="LCD cursor Home\0";
const uint8_t customsymbol1[] PROGMEM="Define symbol\0";
const uint8_t customsymbol2[] PROGMEM="at CGRAM addr=0\0";
const uint8_t customsymbolout[] PROGMEM="Output symbol\0";
const uint8_t shift[] PROGMEM="<-Shift->\0";
const uint8_t shiftdemo[] PROGMEM="Shift DEMO\0";
const uint8_t lcdblank[] PROGMEM="LCD blank DEMO\0";
const uint8_t lcdanimation[] PROGMEM="LCD animation DEMO\0";
// custom LCD characters
const uint8_t backslash[] PROGMEM=
{
0b00000000,//back slash
0b00010000,
0b00001000,
0b00000100,
0b00000010,
0b00000001,
0b00000000,
0b00000000
};
//delay 1s
void delay1s(void)
{
uint8_t i;
for(i=0;i<100;i++)
{
_delay_ms(10);
}
}
//demonstration of shift
void demoshift(void)
{
LCDclr();
CopyStringtoLCD(shift, 3, 0);
delay1s();
CopyStringtoLCD(welcomeln1, 3, 1);
for(uint8_t i=0;i<5;i++)
{
delay1s();
LCDshiftLeft(1);
delay1s();
LCDshiftRight(1);
}
}
//demostration of blank
void demolcdblank(void)
{
LCDclr();
CopyStringtoLCD(lcdblank, 0, 0);
for(uint8_t i=0;i<5;i++)
{
LCDblank();
delay1s();
LCDvisible();
delay1s();
}
}
//demonstration of animation
void demoanimation(void)
{
LCDclr();
CopyStringtoLCD(customsymbol1, 0, 0);
CopyStringtoLCD(customsymbol2, 0, 1);
delay1s();
LCDdefinechar(backslash,0);
LCDclr();
CopyStringtoLCD(customsymbolout, 0, 0);
LCDGotoXY(8, 1);
LCDsendChar(0);
delay1s();
LCDclr();
CopyStringtoLCD(lcdanimation, 0, 0);
for(uint8_t i=0;i<3;i++)
{
LCDGotoXY(8, 1);
LCDsendChar(0);
delay1s();
LCDGotoXY(8, 1);
LCDsendChar('-');
delay1s();
LCDGotoXY(8, 1);
LCDsendChar('/');
delay1s();
LCDGotoXY(8, 1);
LCDsendChar('|');
delay1s();
LCDGotoXY(8, 1);
LCDsendChar(0);
delay1s();
LCDGotoXY(8, 1);
LCDsendChar('-');
delay1s();
LCDGotoXY(8, 1);
LCDsendChar('/');
delay1s();
LCDGotoXY(8, 1);
LCDsendChar('|');
delay1s();
}
}
int main(void)
{
LCDinit();//init LCD 8 bit, dual line, cursor right
LCDclr();//clears LCD
CopyStringtoLCD(curhome, 0, 0);//Cursor home and display message
delay1s();
LCDclr();//clears LCD
LCDhome();//cursonr home
while(1)//loop demos
{
demoshift();
demolcdblank();
demoanimation();
}
return 0;
}
|
lcd_lib.c:
Kodas: |
#include "lcd_lib.h"
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
void LCDsendChar(uint8_t ch) //Sends Char to LCD
{
LDP=(ch&0b11110000);
LCP|=1<<LCD_RS;
LCP|=1<<LCD_E;
_delay_ms(1);
LCP&=~(1<<LCD_E);
LCP&=~(1<<LCD_RS);
_delay_ms(1);
LDP=((ch&0b00001111)<<4);
LCP|=1<<LCD_RS;
LCP|=1<<LCD_E;
_delay_ms(1);
LCP&=~(1<<LCD_E);
LCP&=~(1<<LCD_RS);
_delay_ms(1);
}
void LCDsendCommand(uint8_t cmd) //Sends Command to LCD
{
LDP=(cmd&0b11110000);
LCP|=1<<LCD_E;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
LDP=((cmd&0b00001111)<<4);
LCP|=1<<LCD_E;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
}
void LCDinit(void)//Initializes LCD
{
_delay_ms(15);
LDP=0x00;
LCP=0x00;
LDDR|=1<<LCD_D7|1<<LCD_D6|1<<LCD_D5|1<<LCD_D4;
LCDR|=1<<LCD_E|1<<LCD_RW|1<<LCD_RS;
//---------one------
LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4; //4 bit mode
LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
//-----------two-----------
LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|1<<LCD_D4; //4 bit mode
LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
//-------three-------------
LDP=0<<LCD_D7|0<<LCD_D6|1<<LCD_D5|0<<LCD_D4; //4 bit mode
LCP|=1<<LCD_E|0<<LCD_RW|0<<LCD_RS;
_delay_ms(1);
LCP&=~(1<<LCD_E);
_delay_ms(1);
//--------4 bit--dual line---------------
LCDsendCommand(0b00101000);
//-----increment address, cursor shift------
LCDsendCommand(0b00001110);
}
void LCDclr(void) //Clears LCD
{
LCDsendCommand(1<<LCD_CLR);
}
void LCDhome(void) //LCD cursor home
{
LCDsendCommand(1<<LCD_HOME);
}
void LCDstring(uint8_t* data, uint8_t nBytes) //Outputs string to LCD
{
register uint8_t i;
// check to make sure we have a good pointer
if (!data) return;
// print data
for(i=0; i<nBytes; i++)
{
LCDsendChar(data[i]);
}
}
void LCDGotoXY(uint8_t x, uint8_t y) //Cursor to X Y position
{
register uint8_t DDRAMAddr;
// remap lines into proper order
switch(y)
{
case 0: DDRAMAddr = LCD_LINE0_DDRAMADDR+x; break;
case 1: DDRAMAddr = LCD_LINE1_DDRAMADDR+x; break;
case 2: DDRAMAddr = LCD_LINE2_DDRAMADDR+x; break;
case 3: DDRAMAddr = LCD_LINE3_DDRAMADDR+x; break;
default: DDRAMAddr = LCD_LINE0_DDRAMADDR+x;
}
// set data address
LCDsendCommand(1<<LCD_DDRAM | DDRAMAddr);
}
//Copies string from flash memory to LCD at x y position
//const uint8_t welcomeln1[] PROGMEM="AVR LCD DEMO\0";
//CopyStringtoLCD(welcomeln1, 3, 1);
void CopyStringtoLCD(const uint8_t *FlashLoc, uint8_t x, uint8_t y)
{
uint8_t i;
LCDGotoXY(x,y);
for(i=0;(uint8_t)pgm_read_byte(&FlashLoc[i]);i++)
{
LCDsendChar((uint8_t)pgm_read_byte(&FlashLoc[i]));
}
}
//defines char symbol in CGRAM
/*
const uint8_t backslash[] PROGMEM=
{
0b00000000,//back slash
0b00010000,
0b00001000,
0b00000100,
0b00000010,
0b00000001,
0b00000000,
0b00000000
};
LCDdefinechar(backslash,0);
*/
void LCDdefinechar(const uint8_t *pc,uint8_t char_code){
uint8_t a, pcc;
uint16_t i;
a=(char_code<<3)|0x40;
for (i=0; i<8; i++){
pcc=pgm_read_byte(&pc[i]);
LCDsendCommand(a++);
LCDsendChar(pcc);
}
}
void LCDshiftLeft(uint8_t n) //Scrol n of characters Right
{
for (uint8_t i=0;i<n;i++)
{
LCDsendCommand(0x1E);
}
}
void LCDshiftRight(uint8_t n) //Scrol n of characters Left
{
for (uint8_t i=0;i<n;i++)
{
LCDsendCommand(0x18);
}
}
void LCDcursorOn(void) //displays LCD cursor
{
LCDsendCommand(0x0E);
}
void LCDcursorOnBlink(void) //displays LCD blinking cursor
{
LCDsendCommand(0x0F);
}
void LCDcursorOFF(void) //turns OFF cursor
{
LCDsendCommand(0x0C);
}
void LCDblank(void) //blanks LCD
{
LCDsendCommand(0x08);
}
void LCDvisible(void) //Shows LCD
{
LCDsendCommand(0x0C);
}
void LCDcursorLeft(uint8_t n) //Moves cursor by n poisitions left
{
for (uint8_t i=0;i<n;i++)
{
LCDsendCommand(0x10);
}
}
void LCDcursorRight(uint8_t n) //Moves cursor by n poisitions left
{
for (uint8_t i=0;i<n;i++)
{
LCDsendCommand(0x14);
}
}
|
lcd_lib.h:
Kodas: |
#ifndef LCD_LIB
#define LCD_LIB
#include <inttypes.h>
#define LCD_RS 0 //define MCU pin connected to LCD RS
#define LCD_RW 1 //define MCU pin connected to LCD R/W
#define LCD_E 2 //define MCU pin connected to LCD E
#define LCD_D4 4 //define MCU pin connected to LCD D3
#define LCD_D5 5 //define MCU pin connected to LCD D4
#define LCD_D6 6 //define MCU pin connected to LCD D5
#define LCD_D7 7 //define MCU pin connected to LCD D6
#define LDP PORTB //define MCU port connected to LCD data pins
#define LCP PORTB //define MCU port connected to LCD control pins
#define LDDR DDRB //define MCU direction register for port connected to LCD data pins
#define LCDR DDRB //define MCU direction register for port connected to LCD control pins
#define LCD_CLR 0 //DB0: clear display
#define LCD_HOME 1 //DB1: return to home position
#define LCD_ENTRY_MODE 2 //DB2: set entry mode
#define LCD_ENTRY_INC 1 //DB1: increment
#define LCD_ENTRY_SHIFT 0 //DB2: shift
#define LCD_ON_CTRL 3 //DB3: turn lcd/cursor on
#define LCD_ON_DISPLAY 2 //DB2: turn display on
#define LCD_ON_CURSOR 1 //DB1: turn cursor on
#define LCD_ON_BLINK 0 //DB0: blinking cursor
#define LCD_MOVE 4 //DB4: move cursor/display
#define LCD_MOVE_DISP 3 //DB3: move display (0-> move cursor)
#define LCD_MOVE_RIGHT 2 //DB2: move right (0-> left)
#define LCD_FUNCTION 5 //DB5: function set
#define LCD_FUNCTION_8BIT 4 //DB4: set 8BIT mode (0->4BIT mode)
#define LCD_FUNCTION_2LINES 3 //DB3: two lines (0->one line)
#define LCD_FUNCTION_10DOTS 2 //DB2: 5x10 font (0->5x7 font)
#define LCD_CGRAM 6 //DB6: set CG RAM address
#define LCD_DDRAM 7 //DB7: set DD RAM address
// reading:
#define LCD_BUSY 7 //DB7: LCD is busy
#define LCD_LINES 2 //visible lines
#define LCD_LINE_LENGTH 16 //line length (in characters)
// cursor position to DDRAM mapping
#define LCD_LINE0_DDRAMADDR 0x00
void LCDsendChar(uint8_t); //forms data ready to send to 74HC164
void LCDsendCommand(uint8_t); //forms data ready to send to 74HC164
void LCDinit(void); //Initializes LCD
void LCDclr(void); //Clears LCD
void LCDhome(void); //LCD cursor home
void LCDstring(uint8_t*, uint8_t); //Outputs string to LCD
void LCDGotoXY(uint8_t, uint8_t); //Cursor to X Y position
void CopyStringtoLCD(const uint8_t*, uint8_t, uint8_t);//copies flash string to LCD at x,y
void LCDdefinechar(const uint8_t *,uint8_t);//write char to LCD CGRAM
void LCDshiftRight(uint8_t); //shift by n characters Right
void LCDshiftLeft(uint8_t); //shift by n characters Left
void LCDcursorOn(void); //Underline cursor ON
void LCDcursorOnBlink(void); //Underline blinking cursor ON
void LCDcursorOFF(void); //Cursor OFF
void LCDblank(void); //LCD blank but not cleared |
|
|
|
|
|
|
|
|
|
|
|
Google paieška forume |
|
|
Naujos temos forume |
|
|
FS25 Tractors
Farming Simulator 25 Mods,
FS25 Maps,
FS25 Trucks |
|
ETS2 Mods
ETS2 Trucks,
ETS2 Bus,
Euro Truck Simulator 2 Mods
|
|
FS22 Tractors
Farming Simulator 22 Mods,
FS22 Maps,
FS25 Mods |
|
VAT calculator
VAT number check,
What is VAT,
How much is VAT |
|
LEGO
Mänguköök,
mudelautod,
nukuvanker |
|
Thermal monocular
Thermal vision camera,
Night vision ar scope,
Night vision spotting scope |
|
FS25 Mods
FS25 Harvesters,
FS25 Tractors Mods,
FS25 Maps Mods |
|
Dantų protezavimas
All on 4 implantai,
Endodontija mikroskopu,
Dantų implantacija |
|
FS25 Mods
FS25 Maps,
FS25 Cheats,
FS25 Install Mods |
|
GTA 6 Weapons
GTA 6 Characters,
GTA 6 Map,
GTA 6 Vehicles |
|
FS25 Mods
Farming Simulator 25 Mods,
FS25 Maps |
|
ATS Trailers
American Truck Simulator Mods,
ATS Trucks,
ATS Maps |
|
|
|