//Строка перемещается слева на право.Частота 4МГц.
#include<p18cxxx.h>
#include<delays.h>
#include<string.h>
#pragma config OSC=RC
#pragma config WDT=OFF
#pragma config LVP=OFF
#pragma config BOR=OFF
#pragma config MCLRE=OFF
#define LCD PORTB
#define RS PORTBbits.RB5
#define E PORTBbits.RB4
char str1[]="I am PIC18F1320! How are you?";
#pragma code
void SendLCDdata(char data,char rs)
{
LCD=(data>>4)&0x0f;
RS=rs;
E=1;
Nop();
E=0;
Delay10TCYx(4);
LCD=data&0x0f;
RS=rs;
E=1;
Nop();
E=0;
Delay10TCYx(4);
}
void SendLCDnibble(char nibble,char rs)
{
LCD=nibble&0x0f;
RS=rs;
E=1;
Nop();
E=0;
Delay10TCYx(4);
}
void CLR(void)
{
SendLCDdata(1,0);
Delay1KTCYx(1);
}
void InitLCD(void)
{
Delay1KTCYx(20);
SendLCDnibble(3,0);
Delay1KTCYx(4);
SendLCDdata(3,0);
Delay10TCYx(12);
SendLCDdata(0x32,0);
SendLCDdata(0x28,0);
SendLCDdata(0x08,0);
SendLCDdata(0x01,0);
Delay1KTCYx(2);
SendLCDdata(0x06,0);
SendLCDdata(0x0C,0);
}
void SendLCDstring(char *str,char position)
{
int ptr=0;
SendLCDdata(position,0);
while(str[ptr]!=0){
SendLCDdata(str[ptr++],1);
}
}
void scroll(char *str)
{
char a;
char b;
for(a=0;a<=strlen(str);a++)
{
for(b=0;b<=a;b++)
{
SendLCDdata(0x80|a-b,0);
SendLCDdata(str[strlen(str)-b],1);
}
Delay1KTCYx(100);
}
}
void main(void)
{
ADCON1=0x7f;
TRISB=0;
PORTB=0;
InitLCD();
while(1)
{
scroll(str1);
CLR();
}
}
//Строка перемещается справа на лево и слева на права.Частота 4МГц.
#include<p18cxxx.h>
#include<delays.h>
#include<string.h>
#pragma config OSC=RC
#pragma config WDT=OFF
#pragma config LVP=OFF
#pragma config BOR=OFF
#pragma config MCLRE=OFF
#define LCD PORTB
#define RS PORTBbits.RB5
#define E PORTBbits.RB4
char str1[]="I am PIC18F1320! How are you?";
#pragma code
void SendLCDdata(char data,char rs)
{
LCD=(data>>4)&0x0f;
RS=rs;
E=1;
Nop();
E=0;
Delay10TCYx(4);
LCD=data&0x0f;
RS=rs;
E=1;
Nop();
E=0;
Delay10TCYx(4);
}
void SendLCDnibble(char nibble,char rs)
{
LCD=nibble&0x0f;
RS=rs;
E=1;
Nop();
E=0;
Delay10TCYx(4);
}
void CLR(void)
{
SendLCDdata(1,0);
Delay1KTCYx(2);
}
void InitLCD(void)
{
Delay1KTCYx(20);
SendLCDnibble(3,0);
Delay1KTCYx(4);
SendLCDdata(3,0);
Delay10TCYx(12);
SendLCDdata(0x32,0);
SendLCDdata(0x28,0);
SendLCDdata(0x08,0);
SendLCDdata(0x01,0);
Delay1KTCYx(2);
SendLCDdata(0x06,0);
SendLCDdata(0x0C,0);
}
void SendLCDstring(char *str,char position)
{
int ptr=0;
SendLCDdata(position,0);
while(str[ptr]!=0){
SendLCDdata(str[ptr++],1);
}
}
void scrollRight(char *str)
{
char a;
char b;
for(a=0;a<=strlen(str);a++)
{
for(b=0;b<=a;b++)
{
SendLCDdata(0x90-(a-b),0);
SendLCDdata(str[b],1);
}
Delay1KTCYx(100);
}
}
void scrollLeft(char *str)
{
char a;
char b;
for(a=0;a<=strlen(str);a++)
{
for(b=0;b<=a;b++)
{
SendLCDdata(0x80|a-b,0);
SendLCDdata(str[strlen(str)-b],1);
}
Delay1KTCYx(100);
}
}
void main(void)
{
ADCON1=0x7f;
TRISB=0;
PORTB=0;
InitLCD();
while(1)
{
scrollRight(str1);
CLR();
scrollLeft(str1);
CLR();
}
}
//Выводим текст из программной памяти.
#include<p18cxxx.h>
#include<delays.h>
#include<string.h>
#pragma config OSC=RC
#pragma config WDT=OFF
#pragma config LVP=OFF
#pragma config BOR=OFF
#pragma config MCLRE=OFF
#define LCD PORTB
#define RS PORTBbits.RB5
#define E PORTBbits.RB4
far rom char text[]="Eto text is programmnoy pamyati,tak kak v udata pamyati malo registrov.";
#pragma code
void SendLCDdata(char data,char rs)
{
LCD=(data>>4)&0x0f;
RS=rs;
E=1;
Nop();
E=0;
Delay10TCYx(4);
LCD=data&0x0f;
RS=rs;
E=1;
Nop();
E=0;
Delay10TCYx(4);
}
void SendLCDnibble(char nibble,char rs)
{
LCD=nibble&0x0f;
RS=rs;
E=1;
Nop();
E=0;
Delay10TCYx(4);
}
void CLR(void)
{
SendLCDdata(1,0);
Delay1KTCYx(2);
}
void InitLCD(void)
{
Delay1KTCYx(20);
SendLCDnibble(3,0);
Delay1KTCYx(4);
SendLCDdata(3,0);
Delay10TCYx(12);
SendLCDdata(0x32,0);
SendLCDdata(0x28,0);
SendLCDdata(0x08,0);
SendLCDdata(0x01,0);
Delay1KTCYx(2);
SendLCDdata(0x06,0);
SendLCDdata(0x0C,0);
}
void SendLCDstring(char *str,char position)
{
int ptr=0;
SendLCDdata(position,0);
while(str[ptr]!=0){
SendLCDdata(str[ptr++],1);
}
}
void scrollRightFromPgm(far rom char *str)
{
char a;
char b;
for(a=0;a<=strlenpgm(str);a++)
{
for(b=0;b<=a;b++)
{
SendLCDdata(0x90-(a-b),0);
SendLCDdata(str[b],1);
}
Delay1KTCYx(100);
}
}
void scrollLeftFromPgm(far rom char *str)
{
char a;
char b;
for(a=0;a<=strlenpgm(str);a++)
{
for(b=0;b<=a;b++)
{
SendLCDdata(0x80|a-b,0);
SendLCDdata(str[strlenpgm(str)-b],1);
}
Delay1KTCYx(100);
}
}
void main(void)
{
ADCON1=0x7f;
TRISB=0;
PORTB=0;
InitLCD();
while(1)
{
scrollRightFromPgm(text);
CLR();
scrollLeftFromPgm(text);
CLR();
}
}