Trích:
Nguyên văn bởi tkpro
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ũ.
hì
|
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ả: