#include "test.h"
#include "..\commandes.h"
#define OK 'a'
#define C_DELAY 5
void init()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_timer_4(T4_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_LOW|-2);
setup_low_volt_detect(FALSE);
setup_oscillator(False);
set_tris_b(0b10011111);
set_tris_c(0b10000000);
set_tris_d(0b00000000);
set_tris_f(0b00000000);
set_tris_j(0b00000000);
}
//-------------------------------------------------------------------------------
void datalcd( int8 data ) // Send one byte of data to LCD
{
output_f((data));
//output_d((data));
delay_cycles(C_DELAY);
output_bit(ENABLE,1);
delay_cycles(C_DELAY);
output_bit(ENABLE,0);
}
//-------------------------------------------------------------------------------
void comlcd(int8 a){
output_bit(A0,1);
delay_cycles(C_DELAY);
output_f((a));
delay_cycles(C_DELAY);
output_bit(ENABLE,1);
delay_cycles(C_DELAY);
output_bit(ENABLE,0);
delay_cycles(C_DELAY);
output_bit(A0,0);
}
// -------------------------------------------------------------------------------
void wipescreen( void ) // Wipe all three screen layers
{
//unsigned short t; // Tempo
int t;
comlcd (0x46); // Place cursor on the first data position
datalcd(0x00);
datalcd(0x00);
comlcd (0x42);
datalcd(0x00);
datalcd(0x00);
datalcd(0x00);
datalcd(0x00);
datalcd(0x00);
}
// -------------------------------------------------------------------------------
void init_afficheur(){
output_j(0x00);
output_f(0x00);
// Chip Select
output_bit(CS,0);
// LCD Mode Write
output_bit(RW,0);
delay_ms(20);
// Reset du controlleur
output_bit(RES,0);
delay_ms(20);
output_bit(RES,1);
delay_ms(20);
comlcd(0x40); // System set
datalcd(0x30); // P1 Internal CG ROM, No D6 correction, 8-pixel char height, Single-panel drive
datalcd(0x87); // P2 Cars 8 dots (FX)
datalcd(0x07); // P3 Cars 8 dots high (FY)
datalcd(39); // P4 C/R
datalcd(0x42); // P5 TC/R ???
datalcd(239); // P6 screen is 240 dots high L/F (240-1)
datalcd(0x28); // P7 APL Virtual screen ?
datalcd(0x00); // P8 APH Virtual screen ?
comlcd (0x44); // Set display start adress and display regions
datalcd(0x00); // P1 Adresse Low screen 1
datalcd(0x00); // P2 Adresse High screen 1
datalcd(240); // P3 Number of lines Y (240)
datalcd(0x80); // P4 Adresse Low screen 2
datalcd(0x25); // P5 Adresse High screen 2
datalcd(240); // P6 Number of lines Y (240)
datalcd(0x00); // P7 Adresse Low screen 3
datalcd(0x4B); // P8 Adresse High screen 3
comlcd (0x5A); // Set horiz scroll position
datalcd(0x00); // P1 00 Scroll
comlcd (0x5B); // Set display overlay format
datalcd(0x1D); // P1 Exclusive-OR
comlcd (0x5D); // Cursor form
datalcd(0x07); // P1 Cursor 7 dots
datalcd(0x87); // P2 Block cursor, 8 dots high
comlcd (0x4C); // Set cursor shift direction to right
wipescreen(); // Erase (wipe) data in all tree screens
comlcd (0x59); // Display ON
datalcd(0x54); // Cursor OFF, Layer 1-2-3 à ON
}
void main()
{
init();
init_afficheur();
// Example to send data to screen
comlcd (0x46); // Place cursor in the middle of the screen 1 (aprox)
datalcd(0xC0);
datalcd(0x12);
comlcd (0x42);
datalcd(0x55); // 0101010101 dots in this binary arrangement will be shown
datalcd(0x20);
comlcd (0x59);
// END
while(1){
delay_ms(500);
}
}