PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   Cơ bản về vi điều khiển và PIC (http://www.picvietnam.com/forum/forumdisplay.php?f=8)
-   -   GLCD va PIC (http://www.picvietnam.com/forum/showthread.php?t=13202)

tkpro 04-02-2012 12:29 PM

GLCD va PIC
 
Chào các bác!
Em đang điều khiển GLCD (TG12864A) với CCS và con Pic 18F4550 tuy nhiển chưa chạy. mong các bác trên diễn đàn, ai đã có kinh nghiệm chỉ giáo giúp. Thanks!
đoạn code của em nó như thế này:


//
//-----------------
#include<18f4550.h>
#device *=16 ADC=8
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT,NOLVP, NOCPD, NOWRT
#use delay(clock = 8000000)
#use rs232(baud=56000,parity=n,xmit=pin_C6,rcv=pin_C7)
# byte portA=0xf80 //byte thu 3968
# byte portB=0xf81
# byte portC=0xf82// 3970
# byte portD=0xf83
# byte portE=0xf84 // Byte 3972
#define D_PortE PORTE
#define Dir_PortE TRISE
#define D_PortB PORTB
#define Dir_PortB TRISB
#define D_PortC PORTC
#define Dir_PortC TRISC
#define GLCD_Data PORTD
// cac pin cong A
#define a5 31749 //3968x8+5
//----cac pin cong B--
// cac pin cong C
#bit EN =PORTB.0
#bit RW =PORTB.1
#bit DI =PORTB.2
// cac pin cong D
// cac pin cong E
#bit CS1= portE.0
#bit CS2= portE.1
//void bit_to_byte( )
//////////////////////////
void Enable_Pulse();
void GLCD_ON();
void goto_col(unsigned int x);
void goto_row(unsigned int y);
void GLCD_Clrln(unsigned int ln);
void GLCD_CLR();
void GLCD_Write(unsigned int b);
void GOTO_XY(unsigned int x,unsigned int y);
//signed char i;
// Tao xung Enable
int k,c;
void Enable_Pulse()
{
EN=1;
delay_us(5);
EN=0;
delay_us(5);
}
//
void GLCD_ON()
{
// Active both chips
CS1=0;
CS2=0;
DI=0; // DI=0---> command
RW=0; // RW=0---> Write;
GLCD_Data=0x3F;
//delay_us(5);
Enable_Pulse();
//delay_ms(1);
}
//
void goto_col(unsigned int x)
{
unsigned int Col_data;
DI=0;// command;
RW=0;
if(x<64) //left section
{
CS1 = 0; //select chip 1
CS2 = 1; //deselect chip 2
Col_Data = x; //put column address on data port
}
else //right section
{

CS2 = 0;
CS1 = 1;
Col_Data = x-64; //put column address on data port
}
Col_Data = (Col_Data | 0x40 ) & 0x7F; //Command format
GLCD_Data = Col_Data;
Enable_Pulse();
}
//
void goto_row(unsigned int y)
{
unsigned int Col_Data;
DI = 0; //RS low --> command
RW = 0; //RW low --> write
Col_Data = (y | 0xB8 ) & 0xBF; //put row address on data port set command
GLCD_Data = Col_Data;
Enable_Pulse();
}
void GLCD_Clrln(unsigned int ln)
{
int i;
GOTO_XY(0,ln); //At start of line of left side
GOTO_XY(64,ln); //At start of line of right side (Problem)
CS1 = 0;
for(i=0;i<65;i++)
GLCD_Write(0);
}
//
void GLCD_CLR()
{
unsigned int m;
for(m=0;m<8;m++){
GLCD_Clrln(m);
}
}
//
void GLCD_Write(unsigned int b)
{
DI = 1; //RS high --> data
RW = 0; //RW low --> write
GLCD_Data = b; //put data on data port
delay_us(1);
Enable_Pulse();
}
//
void GOTO_XY(unsigned int x,unsigned int y)
{
goto_col(x);
goto_row(y);
}
void main()
{
set_tris_A(0);
set_tris_B(0);
set_tris_C(0);
set_tris_D(0);
set_tris_E(0);
delay_ms(200);
while(true)
{
GLCD_ON();
delay_us(10);
//for(c=0;c<=128;c++)
//{
for(k=0;k<128;k++)
{
goto_xy(k,0);
delay_us(10);
glcd_write(1);
}

}
}

tdm 04-02-2012 10:59 PM

Trích:

Nguyên văn bởi tkpro (Post 54073)
Chào các bác!
Em đang điều khiển GLCD (TG12864A) với CCS và con Pic 18F4550 tuy nhiển chưa chạy. mong các bác trên diễn đàn, ai đã có kinh nghiệm chỉ giáo giúp. Thanks!
đoạn code của em nó như thế này:


//
//-----------------
#include<18f4550.h>
#device *=16 ADC=8
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT,NOLVP, NOCPD, NOWRT
#use delay(clock = 8000000)
#use rs232(baud=56000,parity=n,xmit=pin_C6,rcv=pin_C7)
# byte portA=0xf80 //byte thu 3968
# byte portB=0xf81
# byte portC=0xf82// 3970
# byte portD=0xf83
# byte portE=0xf84 // Byte 3972
#define D_PortE PORTE
#define Dir_PortE TRISE
#define D_PortB PORTB
#define Dir_PortB TRISB
#define D_PortC PORTC
#define Dir_PortC TRISC
#define GLCD_Data PORTD
// cac pin cong A
#define a5 31749 //3968x8+5
//----cac pin cong B--
// cac pin cong C
#bit EN =PORTB.0
#bit RW =PORTB.1
#bit DI =PORTB.2
// cac pin cong D
// cac pin cong E
#bit CS1= portE.0
#bit CS2= portE.1
//void bit_to_byte( )
//////////////////////////
void Enable_Pulse();
void GLCD_ON();
void goto_col(unsigned int x);
void goto_row(unsigned int y);
void GLCD_Clrln(unsigned int ln);
void GLCD_CLR();
void GLCD_Write(unsigned int b);
void GOTO_XY(unsigned int x,unsigned int y);
//signed char i;
// Tao xung Enable
int k,c;
void Enable_Pulse()
{
EN=1;
delay_us(5);
EN=0;
delay_us(5);
}
//
void GLCD_ON()
{
// Active both chips
CS1=0;
CS2=0;
DI=0; // DI=0---> command
RW=0; // RW=0---> Write;
GLCD_Data=0x3F;
//delay_us(5);
Enable_Pulse();
//delay_ms(1);
}
//
void goto_col(unsigned int x)
{
unsigned int Col_data;
DI=0;// command;
RW=0;
if(x<64) //left section
{
CS1 = 0; //select chip 1
CS2 = 1; //deselect chip 2
Col_Data = x; //put column address on data port
}
else //right section
{

CS2 = 0;
CS1 = 1;
Col_Data = x-64; //put column address on data port
}
Col_Data = (Col_Data | 0x40 ) & 0x7F; //Command format
GLCD_Data = Col_Data;
Enable_Pulse();
}
//
void goto_row(unsigned int y)
{
unsigned int Col_Data;
DI = 0; //RS low --> command
RW = 0; //RW low --> write
Col_Data = (y | 0xB8 ) & 0xBF; //put row address on data port set command
GLCD_Data = Col_Data;
Enable_Pulse();
}
void GLCD_Clrln(unsigned int ln)
{
int i;
GOTO_XY(0,ln); //At start of line of left side
GOTO_XY(64,ln); //At start of line of right side (Problem)
CS1 = 0;
for(i=0;i<65;i++)
GLCD_Write(0);
}
//
void GLCD_CLR()
{
unsigned int m;
for(m=0;m<8;m++){
GLCD_Clrln(m);
}
}
//
void GLCD_Write(unsigned int b)
{
DI = 1; //RS high --> data
RW = 0; //RW low --> write
GLCD_Data = b; //put data on data port
delay_us(1);
Enable_Pulse();
}
//
void GOTO_XY(unsigned int x,unsigned int y)
{
goto_col(x);
goto_row(y);
}
void main()
{
set_tris_A(0);
set_tris_B(0);
set_tris_C(0);
set_tris_D(0);
set_tris_E(0);
delay_ms(200);
while(true)
{
GLCD_ON();
delay_us(10);
//for(c=0;c<=128;c++)
//{
for(k=0;k<128;k++)
{
goto_xy(k,0);
delay_us(10);
glcd_write(1);
}

}
}

bạn đang sử dụng chân:portE.0 và portE.1
thêm lệnh này SETUP_ADC_PORTS(NO_ANALOGS); vào hàm main thì nó chạy thôi.

tkpro 07-02-2012 04:21 PM

Trích:

Nguyên văn bởi tdm (Post 54091)
bạn đang sử dụng chân:portE.0 và portE.1
thêm lệnh này SETUP_ADC_PORTS(NO_ANALOGS); vào hàm main thì nó chạy thôi.

Thanks!
Tôi đã thêm lệnh SETUP_ADC_PORTS(NO_ANALOGS); rồi tuy nhiên nó vẫn kô chạy bạn ah
Màn hình nó vẫn như cũ.

tdm 09-02-2012 02:35 PM

1 Attachment(s)
Trích:

Nguyên văn bởi tkpro (Post 54161)
Thanks!
Tôi đã thêm lệnh SETUP_ADC_PORTS(NO_ANALOGS); rồi tuy nhiên nó vẫn kô chạy bạn ah
Màn hình nó vẫn như cũ.

Mô phỏng thử code của bạn:
Code:

#include<18f4550.h>
#device *=16 ADC=8
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, NOBROWNOUT,NOLVP, NOCPD, NOWRT
#use delay(clock = 8000000)
#use rs232(baud=56000,parity=n,xmit=pin_C6,rcv=pin_C7)
# byte portA=0xf80 //byte thu 3968
# byte portB=0xf81
# byte portC=0xf82// 3970
# byte portD=0xf83
# byte portE=0xf84 // Byte 3972
#define D_PortE PORTE
#define Dir_PortE TRISE
#define D_PortB PORTB
#define Dir_PortB TRISB
#define D_PortC PORTC
#define Dir_PortC TRISC
#define GLCD_Data PORTD
// cac pin cong A
#define a5 31749 //3968x8+5
//----cac pin cong B--
// cac pin cong C
#bit EN =PORTB.0
#bit RW =PORTB.1
#bit DI =PORTB.2
// cac pin cong D
// cac pin cong E
#bit CS1= portE.0
#bit CS2= portE.1
//void bit_to_byte( )
//////////////////////////
void Enable_Pulse();
void GLCD_ON();
void goto_col(unsigned int x);
void goto_row(unsigned int y);
void GLCD_Clrln(unsigned int ln);
void GLCD_CLR();
void GLCD_Write(unsigned int b);
void GOTO_XY(unsigned int x,unsigned int y);
//signed char i;
// Tao xung Enable
int k,c;
void Enable_Pulse()
{
EN=1;
delay_us(5);
EN=0;
delay_us(5);
}
//
void GLCD_ON()
{
// Active both chips
CS1=0;
CS2=0;
DI=0; // DI=0---> command
RW=0; // RW=0---> Write;
GLCD_Data=0x3F;
//delay_us(5);
Enable_Pulse();
//delay_ms(1);
}
//
void goto_col(unsigned int x)
{
unsigned int Col_data;
DI=0;// command;
RW=0;
if(x<64) //left section
{
CS1 = 0; //select chip 1
CS2 = 1; //deselect chip 2
Col_Data = x; //put column address on data port
}
else //right section
{

CS2 = 0;
CS1 = 1;
Col_Data = x-64; //put column address on data port
}
Col_Data = (Col_Data | 0x40 ) & 0x7F; //Command format
GLCD_Data = Col_Data;
Enable_Pulse();
}
//
void goto_row(unsigned int y)
{
unsigned int Col_Data;
DI = 0; //RS low --> command
RW = 0; //RW low --> write
Col_Data = (y | 0xB8 ) & 0xBF; //put row address on data port set command
GLCD_Data = Col_Data;
Enable_Pulse();
}
void GLCD_Clrln(unsigned int ln)
{
int i;
GOTO_XY(0,ln); //At start of line of left side
GOTO_XY(64,ln); //At start of line of right side (Problem)
CS1 = 0;
for(i=0;i<65;i++)
GLCD_Write(0);
}
//
void GLCD_CLR()
{
unsigned int m;
for(m=0;m<8;m++){
GLCD_Clrln(m);
}
}
//
void GLCD_Write(unsigned int b)
{
DI = 1; //RS high --> data
RW = 0; //RW low --> write
GLCD_Data = b; //put data on data port
delay_us(1);
Enable_Pulse();
}
//
void GOTO_XY(unsigned int x,unsigned int y)
{
goto_col(x);
goto_row(y);
}
void main()
{
set_tris_A(0);
set_tris_B(0);
set_tris_C(0);
set_tris_D(0);
set_tris_E(0);
SETUP_ADC_PORTS(NO_ANALOGS);
delay_ms(200);

GLCD_ON();
delay_us(10);
//for(c=0;c<=128;c++)
//{
for(k=0;k<128;k++)
{
goto_xy(k,0);
delay_us(10);
glcd_write(1);
}
while(true)
{
}
}

kêt quả:

tkpro 09-02-2012 05:26 PM

Thanks
 
mình đã sửa và chạy Ok rùi
con LCD của mình chọn chíp các chân CS1, CS2 tích cực mức cao.(nên chỉ thay CS1, CS2 là OK)
Thanks tdm
các bác cho em hỏi thêm là:
Tại sao khi tôi setup ADC của Pic là:
Setup_ADC_ports(AN0_AN1_AN3);
Setup_ADC(adc_clock_internal);
nó lại báo lỗi thế này:
*** Error 12 "D:\Pic & DSPIC\Pic & DSPIC\Code\GLCD\k.c" Line 170(19,30): Undefined identifier AN0_AN1_AN3

hein_ts 24-12-2012 12:57 AM

Bạn đọc trong header file là biết ngay thôi. hjhj


Múi giờ GMT. Hiện tại là 02:13 PM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam