Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <parapin.h>
- #include <sys/io.h>
- #define BASEPORT 0x378
- // correspondances LCD PARA pin à pin
- #define LCD_E LP_PIN01
- #define LCD_D0 LP_PIN02
- #define LCD_D1 LP_PIN03
- #define LCD_D2 LP_PIN04
- #define LCD_D3 LP_PIN05
- #define LCD_D4 LP_PIN06
- #define LCD_D5 LP_PIN07
- #define LCD_D6 LP_PIN08
- #define LCD_D7 LP_PIN09
- // Si on a connecté le pin LCD 5 au pin 16 du PP et non pas au 14
- #define LCD_RW LP_PIN16
- #define LCD_RS LP_PIN17
- // Peut etre que faire #define LP_CONTROL_PINS LP_SWITCHABLE_PINS suffit
- #define LP_CONTROL_PINS (LP_PIN01 | LP_PIN16 | LP_PIN17)
- //
- #define LCD_CNTL LP_CONTROL_PINS
- // LCD_DATA peut aussi être vu comme un octet
- #define LCD_DATA LP_DATA_PINS
- // instructions du LCD
- #define LCD_iClearDisplay 0x01
- #define LCD_iReturnHome 0x02
- #define LCD_iEntryModeSet 0x04
- #define LCD_iDisplayOnOff 0x08
- #define LCD_iShift 0x10
- #define LCD_iFunctionSet 0x20
- #define LCD_iSetCGRAMAddr 0x40
- #define LCD_iSetDDRAMAddr 0x80
- static char LCD_DDRAM_ADDR; // adresse actuelle dans la mémoire DDRAM du LCD
- static char LCD_LINE; // ligne actuelle sur le LCD
- void set_lcd_data(unsigned char data) {
- // char et non int afin d'être sur de n'écrire qu'un octet
- // On utilise le fait que LCD_DATA est aussi visible comme un octet
- // pour set-pin
- set_pin(data);
- }
- void LCD_BusyCheck() {
- clear_pin(LCD_DATA);
- pin_input_mode(LCD_DATA); // Port de données en lecture
- clear_pin(LCD_RS); // LCD en mode instruction
- set_pin(LCD_RW); // LCD en mode écriture
- do {
- set_pin(LCD_E);
- clear_pin(LCD_E); // créneau pour lancer l'opération
- } while (pin_is_set(LCD_D7)); // teste le signal busy
- clear_pin(LCD_RW); // LCD en mode lecture (pour éviter les conflits de bus)
- pin_output_mode(LCD_DATA); // Port de données en écriture
- }
- void LCD_SendCommand(unsigned char command, unsigned char data) {
- LCD_BusyCheck();
- clear_pin(LCD_RW|LCD_RS); // LCD en mode lecture + instruction
- set_lcd_data(command|data); // On place la donnée dans le bus
- set_pin(LCD_E);
- clear_pin(LCD_E); // créneau pour lancer l'opération
- }
- void LCD_Init() {
- pin_output_mode(LP_DATA_PINS);
- pin_output_mode(LP_CONTROL_PINS);
- clear_pin(LCD_DATA);
- set_lcd_data(0x30);
- //set_pin(LCD_E);
- //clear_pin(LCD_E);
- usleep(200000);
- { //Test
- printf("Turn input LCD_DATA\n" );
- pin_input_mode(LCD_DATA);
- printf("\nData Pin Status: " );
- printf("%s", pin_is_set(LCD_D7)?"1":"0" );
- printf("%s", pin_is_set(LCD_D6)?"1":"0" );
- printf("%s", pin_is_set(LCD_D5)?"1":"0" );
- printf("%s", pin_is_set(LCD_D4)?"1":"0" );
- printf("%s", pin_is_set(LCD_D3)?"1":"0" );
- printf("%s", pin_is_set(LCD_D2)?"1":"0" );
- printf("%s", pin_is_set(LCD_D1)?"1":"0" );
- printf("%s", pin_is_set(LCD_D0)?"1":"0" );
- printf("\n" );
- printf("Expected: 00110000\n" );
- pin_output_mode(LCD_DATA);
- }
- usleep(2000); // Pour l'embarque ou on attend après la mise sous tension plus de 1.5 ms (2 ms)
- clear_pin(LCD_CNTL);
- set_lcd_data(0x30);
- set_pin(LCD_E);
- clear_pin(LCD_E); // On envoie 0011xxxx
- usleep(5000); // attente de plus de 4.1 ms (5 ms)
- set_lcd_data(0x30);
- set_pin(LCD_E);
- clear_pin(LCD_E); // On envoie 0011xxxx
- usleep(128000); // attente de plus de 100 ms (128 ms)
- set_lcd_data(0x30);
- set_pin(LCD_E);
- clear_pin(LCD_E); // On envoie 0011xxxx
- { //Test
- pin_input_mode(LCD_DATA);
- printf("\nData Pin Status: " );
- printf("%s", pin_is_set(LCD_D7)?"1":"0" );
- printf("%s", pin_is_set(LCD_D6)?"1":"0" );
- printf("%s", pin_is_set(LCD_D5)?"1":"0" );
- printf("%s", pin_is_set(LCD_D4)?"1":"0" );
- printf("%s", pin_is_set(LCD_D3)?"1":"0" );
- printf("%s", pin_is_set(LCD_D2)?"1":"0" );
- printf("%s", pin_is_set(LCD_D1)?"1":"0" );
- printf("%s", pin_is_set(LCD_D0)?"1":"0" );
- printf("\n" );
- printf("Expected: 00110000\n" );
- pin_output_mode(LCD_DATA);
- }
- // a partir de maintenant on pourra tester le signal BUSY pour l'attente
- LCD_SendCommand(LCD_iFunctionSet,
- 0x18); // Interface 8 bits, 2 lignes, caracteres 5*8 pixels
- LCD_SendCommand(LCD_iDisplayOnOff,
- 0x04); // Allumer l'écran
- LCD_SendCommand(LCD_iEntryModeSet,
- 0x06); // sens g. à d., décalage=0
- LCD_SendCommand(LCD_iClearDisplay,
- 0x00); // effacer l'écran
- LCD_DDRAM_ADDR = 0;
- LCD_LINE = 1;
- }
- void LCD_SendChar(unsigned char c) {
- LCD_BusyCheck();
- clear_pin(LCD_RW); // LCD en mode lecture
- set_pin(LCD_RS); // LCD en mode données
- set_lcd_data(c); // place la donnée sur le bus
- set_pin(LCD_E);
- clear_pin(LCD_E); // créneau pour lancer l'opération
- LCD_DDRAM_ADDR++;
- }
- void LCD_SendString(unsigned char *string)
- {
- while(*string) { //till string ends
- LCD_SendChar(*string++); //send characters one by one
- }
- }
- int main (int argc, char * argv[]) {
- int parapin_init_success = 0;
- if (argc == 1) {
- printf("Usage: paralcd prend au moins un argument. \n" );
- return 1;
- }
- if (ioperm(BASEPORT, 3, 1)) {
- perror("paralcd::ioperm" );
- return 1;
- }
- parapin_init_success = pin_init_user(BASEPORT);
- if (parapin_init_success != 0) {
- printf("Echec de l'initialisation de parapin. \n" );
- }
- LCD_Init();
- LCD_SendString("Jovalise" );
- clear_pin(LP_DATA_PINS|LP_CONTROL_PINS); // vu dans les exemples de parapin
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment