Futura Sciences
Image de la rubrique en cours

Forum FS Generation

Précédent   Vous êtes ici : Forum FS Generation » Futura Technique » Électronique

Découvrir d'autres sujets sur ces thèmes : , , ,


Réponse
Vieux 18/04/2006, 20h03   Sujet Code C pour LCD T6963C et 16F877 - Message #1
FandeMuse
 
Date d'inscription: mars 2006
Localisation: Vers Genève
Âge: 18
Messages: 85
Code C pour LCD T6963C et 16F877
Depuis peu, je me suis décider de controler un LCD graphique avec un 16F877 mais celui-ci a un driver Toshiba T6963C.Et quand je teste le programme un peu modifier car sinon il ne fonctionnait pas, il reste bloqué dans la fonction glcd_writebyte(), pourquoi n'en sort-il pas et continue ce qu'il a à faire.

code : ex_glcd.c
Citation:
#include <16F877.h>
#use delay(clock=4000000)
#fuses HS,NOWDT,NOPROTECT,NOLVP
#include <ex_glcd.h>
#include <function.c>
#byte data = 8
#byte portd=8 //// /WR - - C4;/RD - - C5;C//D- - C6;/RST- - C7;DATA0-7 PORTD0-7 ////

void main() {
set_tris_a(0xff);set_tris_a(0x 00);set_tris_b(0xff);set_tris_ b(0x00);set_tris_d(0xff);set_t ris_d(0x00);set_tris_c(0xff);s et_tris_c(0x00);LCD=portd=data =0x00;
set_tris_c(0x00); // graphic lcd control lines all output
set_tris_b(0xff); //TRIS DATA bus,note:control bus always outputs

glcd_init();
glcd_WriteByte(1, (LCDModeSet|LCDMode_XOR));
glcd_WriteByte(1, (LCDDispMode|LCDDisp_TXT|LCDDi sp_GRH));
glcd_putc("hello");
}

code function.c
Citation:
#byte data = 8
#byte portd=8 //// /WR - - C4;/RD - - C5;C//D- - C6;/RST- - C7;DATA0-7 PORTD0-7 ////

const int TextHome = 0x78;
const int TextArea = 0x1E; // how many bytes before a new line
const int GraphicsHome = 0x00;
const int GraphicsArea = 0x1E; // how many bytes before a new line

const int AutoModeWrite = 0xB0;
const int AutoModeRead = 0xB1;
const int AutoModeReset = 0xB2;

const int LCDModeSet = 0x80; // send this OR'd with the following
const int LCDMode_OR = 0b0000;
const int LCDMode_XOR = 0b0001;
const int LCDMode_AND = 0b0010;
const int LCDMode_TA = 0b0100; // TEXT ATTRIBUTE mode.
const int LCDMode_RAM = 0b1000; // 1=CG RAM, 0=internal CG ROM

const int LCDSetCursorPtr = 0x21; // cursor address
const int LCDSetCursorSize = 0xA0; // 1 line cursor

const int LCDDispMode = 0x90; // send this OR'd with the following
const int LCDDisp_BLK = 0b0001;
const int LCDDisp_CUR = 0b0010;
const int LCDDisp_TXT = 0b0100;
const int LCDDisp_GRH = 0b1000;

struct lcd_pin_def
{
BOOLEAN unused1; // C0
BOOLEAN unused2; // C1
BOOLEAN unused3; // C2
BOOLEAN unused4; // C3
BOOLEAN w_bar; // C4 Write bar active low
BOOLEAN r_bar; // C5 Read bar active low
BOOLEAN cd; // C6 Command/Data BAR 1=command 0=data
BOOLEAN reset_bar; // C7 Reset active low
};
struct lcd_pin_def LCD;

#byte LCD = 7 // portC address on 16F877

void glcd_init()
{
set_tris_a(0xff);set_tris_a(0x 00);set_tris_b(0xff);set_tris_ b(0x00);set_tris_d(0xff);set_t ris_d(0x00);set_tris_c(0xff);s et_tris_c(0x00);LCD=portd=data =0x00;
set_tris_c(0x00); // graphic lcd control lines all output
set_tris_b(0xff); //TRIS DATA bus,note:control bus always outputs

LCD.w_bar = 1; // INITIAL STATES OF CONTROL PINS
LCD.r_bar = 1; //
LCD.cd = 1; // command

LCD.reset_bar = 0; // perform a reset
delay_us(10); // delay for a reset
LCD.reset_bar = 1; // run

glcd_WriteCmd2(TextHome, 0x40);
glcd_WriteCmd2(TextArea, 0x41);
glcd_WriteCmd2(GraphicsHome, 0x42);
glcd_WriteCmd2(GraphicsArea, 0x43);

// set address to 0
glcd_WriteCmd2(0x0000, 0x24);
glcd_WriteCmd2(0x0000, 0x24);

// Clear all RAM of LCD (8k)
glcd_WriteByte(1, AutoModeWrite);
glcd_WriteByte(1, AutoModeReset);
}

void glcd_WriteByte(int cd2, int data)
{
int status = 0, temp = 0;
set_tris_d(0xff);
LCD.w_bar = 1;
LCD.r_bar= 0;
LCD.cd = 1;
status = portd;

while (status != 0x03) { // is LCD busy?
LCD.r_bar= 0;
portd = temp;
LCD.r_bar = 1;
status = temp & 0x03;
}

set_tris_d(0x00);
LCD.cd = cd2; // Command/Data bar
portd = data;
LCD.r_bar = 1; // not read
LCD.w_bar = 0; // write
LCD.w_bar = 1; // release
}

void glcd_WriteByteAuto(int data)
{
int status = 0, temp = 0; // status bits ARE DIFFERENT BITS THAN NORMAL
set_tris_b(0xff);
LCD.w_bar = 1;
LCD.r_bar = 1;
LCD.cd = 1; // defaults
status=portd;

while (status != 0x08) { // is LCD busy?
LCD.r_bar = 0;
temp = portd;
LCD.r_bar = 1;
status = temp & 0x08;
}

set_tris_d(0x00); // All outputs
LCD.cd = 0; // This is always data, cd=0
portd = data; // Put data on data bus
LCD.w_bar = 0; // write
LCD.w_bar = 1; // release
}

void glcd_WriteCmd1(int data, int cmd)
{
glcd_WriteByte(0, data);
glcd_WriteByte(1, cmd);
}

void glcd_WriteCmd2(int data, int cmd)
{
glcd_WriteByte(0, data & 0xff);
glcd_WriteByte(0, data>>8);
glcd_WriteByte(1, cmd);
}

int glcd_ReadByte(void)
{
int data = 0, status = 0, temp = 0;
set_tris_b(0xff);
LCD.w_bar = 1;
LCD.r_bar = 1;
LCD.cd = 1; // defaults
status=portd;

#asm nop #endasm

while (status != 0x03) { // is LCD busy?
LCD.r_bar = 0;
temp = portd;
LCD.r_bar = 1;
status = temp & 0x03;
}

LCD.cd = 0; // Command/Data bar
LCD.r_bar = 0; // read
/////////////////////////////////////////////////////////
#asm nop #endasm // THIS PAUSE IS VERY NESSESARY !!!//
/////////////////////////////////////////////////////////
data = portd;
LCD.r_bar = 1;
LCD.cd = 1;
return data; // Return the read data
}

void glcd_putc(char c) {
glcd_WriteCmd1(c - 0x20, 0xc0);
}

void glcd_gotoxy(int x, int y, int text) { // sets memory location to screen location x, y
// location 1,1 is upper left corner; text = 1 (text area), text = 0 (graphics area)
int location, home;
int line;

if (!text) {
home = GraphicsHome;
line = GraphicsArea;
}
else {
home = TextHome;
line = TextArea;
}

location = home + (((int)y - 1) * line) + x - 1;
glcd_WriteCmd2(location, 0x24);
}

code : ex_glcd.h
Citation:
extern int glcd_ReadByte(void);
extern void glcd_WriteByte(int cd, int data);
extern void glcd_WriteByteAuto(int data);
extern void glcd_WriteCmd2(int data, int cmd);
extern void glcd_WriteCmd1(int data, int cmd);
extern void glcd_gotoxy(int x, int y, int1 text);
extern void glcd_init();


Merci d'avance
FandeMuse est déconnecté   Réponse avec citation
Alt Aujourd'hui
Publicité

Beitrag Liens sponsorisés

   
Bienvenue
Si ceci est votre première visite, vous devez vous inscrire avant de pouvoir envoyer des messages. En étant inscrit vous pourrez poster votre question, participer aux débats, joindre vos images... alors n'attendez-plus, cela vous prendra 1 minute !

Pour commencer à lire les messages, depuis la page d'accueil des forums, sélectionnez le forum qui vous tente et partez ensuite à sa découverte...

Publicité

A voir aussi
LCD 128x64 T6963C sur PIC16F876 (Forum Électronique)
Driver LCD 2*16 avec PIC 16F877 (Forum Électronique)
lcd clavier 16 touches 16f877 (Forum Électronique)
16f877 et afficheur LCD (Forum Électronique)
Pic 16f877 + Lcd (m6222 + Lc7930 ) (Forum Électronique)






A voir aussi (Futura Sciences n'est pas responsable du contenu de ces publicités)
Réponse



Outils
Modes d'affichage

Règles de messages
Vous pouvez ouvrir de nouvelles discussions : nonoui
Vous pouvez envoyer des réponses : nonoui
Vous pouvez insérer des pièces jointes : nonoui
Vous pouvez modifier vos messages : nonoui

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Navigation rapide


Les dernières actualités
12/05 10:49 - Les stratosphères de Saturne et de la Terre : des cousines proches
11/05 16:02 - L'imagerie médicale numérisée au service de l'anthropologie
11/05 11:58 - Les caprices des supraconducteurs à haute température bientôt élucidés ?
10/05 14:07 - Comment régénérer l'air du vaisseau Orion, en route vers la Lune ?
10/05 10:47 - La Machine à différences de Babbage dans la Silicon Valley
09/05 15:38 - Une épidémie à l'entérovirus EV-71 inquiète les autorités chinoises
09/05 15:37 - Les OMZ, zones de minimum d'oxygène, s'agrandissent dans l'océan mondial

Fuseau horaire GMT +2. Il est actuellement 13h32.

Propulsé par vBulletin
Copyright © 2000 - 2008, Jelsoft Enterprises Ltd. Tous droits réservés.
Traduction par l'association vBulletin francophone