/*
 * File:   lcd_lib.c
 * Author: Adrian
 *
 * Created on August 1, 2019, 12:14 AM
 */

#include "mcc.h"
#include "lcd_lib.h"

void LCD_Clear(void){
    uint8_t LCD_C[]={0x80, 0x01};
    I2C_MasterWrite(LCD_C, 2, LCD_Address, &status);
    __delay_ms(50);
}

void LCD_Write_Data(int LCD_data , int addr){
    uint8_t temp1[] = {0x80, 0x00};
    uint8_t data[]  = {0x70, 0};
    temp1[1]=addr;
    data[1]=LCD_data+0x30;
    I2C_MasterWrite(temp1, 2, LCD_Address, &status);
     while(status == I2C_MESSAGE_PENDING);
    I2C_MasterWrite(data, 2, LCD_Address, &status);
     while(status == I2C_MESSAGE_PENDING);
}

void LCD_Write_Char(char c , int addr){
   
    uint8_t temp1[] = {0x80, 0x00};
    uint8_t data[]  = {0x70, 0};
    temp1[1]=addr;
    data[1]=c;
    I2C_MasterWrite(temp1, 2, LCD_Address, &status);
    while(status == I2C_MESSAGE_PENDING);
    I2C_MasterWrite(data, 2, LCD_Address, &status);
    while(status == I2C_MESSAGE_PENDING);
}

void LCD_Write_int_number(int number, int addr){
    int i = 0, counter = 0;
    uint8_t number_array[16];
    while(number != 0){
        number_array[counter] = number % 10;
        number = number / 10;
        counter++;
    }
    for(i = 1;i <= counter;i++){
        LCD_Write_Data(number_array[counter - i],addr + i);
    }
}

void LCD_Write_String(char *string,int addr){
    int string_increment;
    uint8_t cell = addr;
    for(string_increment=0;string[string_increment]!='\0';string_increment++){
       LCD_Write_Char(string[string_increment],cell);
       cell++;
    }   
}