Пример #1
0
void putsXLCD(unsigned char *buffer)
{
        while(*buffer)                  // Write data to LCD up to null
        {
//                while(BusyXLCD());      // Wait while LCD is busy
			if (buffer[0] > 191)
				WriteDataXLCD(simbolsLatin[buffer[0] - 192]);
			else
				WriteDataXLCD(*buffer); // Write character to LCD
			buffer++;               // Increment buffer
        }
        return;
}
Пример #2
0
void FloatToLCD(float data, unsigned char countDs, unsigned char pos)
{
	unsigned int tempSt = 0;
	unsigned int tempDec = 0;
	unsigned char buf[5];
	
	tempSt = (unsigned int)data;
	tempDec = (unsigned int)((data - tempSt)*10);
	
	pos += 4;
	if (tempSt > 9)
		pos--;
	if (tempSt > 99)
		pos--;
	if (tempSt > 999)
		pos--;
	pos -= 2;		
	SetDDRamAddr(pos);
	itoa(tempSt, buf);
	putsXLCD(buf);
	pos++;
	if (tempSt > 9)
		pos++;
	if (tempSt > 99)
		pos ++;
	if (tempSt > 999)
		pos ++;	
	SetDDRamAddr(pos);
	WriteDataXLCD(0x2E);
	pos++;
	SetDDRamAddr(pos);
	itoa(tempDec, buf);
	putsXLCD(buf);			
}
Пример #3
0
void initLCD(void)
{
        OpenXLCD(FOUR_BIT & LINES_5X7);
        SetDDRamAddr(0x00);
        WriteDataXLCD('1');
	WriteCmdXLCD(DON&CURSOR_OFF&BLINK_OFF);
}
Пример #4
0
void putrsXLCD(const rom char *buffer)
{
        while(*buffer)                  // Write data to LCD up to null
        {
                while(BusyXLCD());      // Wait while LCD is busy
                WriteDataXLCD(*buffer); // Write character to LCD
                buffer++;               // Increment buffer
        }
        return;
}
/********************************************************************
*       Function Name:  lcd_putc(char lettre)                        *
*       Return Value:   void                                        *
*       Parameters:     lettre: caractère à afficher sur le LCD     *
*       Description:    Cette fonction reprend WriteDataXLCD mais en*
*                       plus gère les caractère spéciaux \n \f \b   *
********************************************************************/
void lcd_putc(char lettre)
{
        while(BusyXLCD());
        switch(lettre){
            case '\f'   : WriteCmdXLCD(0x01);  
                          DelayXLCD();     
                          break; // effacement de l'écran
            case '\n'   : lcd_gotoyx(2,1);        
                          break;               // passage à la ligne
            case '\b'   : WriteCmdXLCD(0x10);  
                          break;                  // recule d'une position
            default     : WriteDataXLCD(lettre);
                          break;                 // écrit la lettre
   }	
}
Пример #6
0
void main(void) {

    //IRCF0_bit=0b0;
    //IRCF1_bit=0b0;
    //IRCF2_bit=0b1;
    //OSCCON=0b100; // 1mhz
    //OSCCON=0b001; // 125 khz

    //OSCCONbits.SCS1=1; // internal oscillator block
    OSCCONbits.IRCF0 = 0b1;
    OSCCONbits.IRCF1 = 0b1;
    OSCCONbits.IRCF2 = 0b1;


    //para 100 (osconbits 210), osciloscopio acusou 250 khz


    short int cont;
    TRISB = 0;
    TRISC = 0;
    /*
    TRISCbits.RC3=0;
    TRISCbits.RC2=0;
    TRISCbits.RC1=0;
    */

    PORTC = 0x00;

     for (cont=0; cont<2; cont++)
        {
         //LATC3=1;
         //LATC2=1;
         //LATC1=1;
         PORTC=0b1111;

        Delay10KTCYx(1000);

         //LATC3=0;
         //LATC2=0;
         //LATC1=0;
         PORTC=0b0000;

        Delay10KTCYx(1000);
        }

    OSCCONbits.IRCF0 = 0b0;
    OSCCONbits.IRCF1 = 0b1;
    OSCCONbits.IRCF2 = 0b1; // 4mhz

    LATC3=0;
    LATC2=0;
    LATC1=0;
    
        Delay10KTCYx(2000);

    	OpenXLCD(FOUR_BIT & LINES_5X7);
        WriteDataXLCD('H');
	WriteCmdXLCD(DON&CURSOR_ON&BLINK_ON);

        char data[]="Finalmente Rodou";
        
    while (1) {

        PORTC=0;

        for (cont= 0b0001 ; cont <= 0b1111 ; cont=cont*2)
        {
        PORTC = cont;
        Delay10KTCYx(10);
        }
        PORTC=0;

        OSCCONbits.IRCF0 = 0b1;
        OSCCONbits.IRCF1 = 0b1;
        OSCCONbits.IRCF2 = 0b0; // 500 khz
        
        while(BusyXLCD());
        WriteCmdXLCD(0x01);
        


	Delay10KTCYx(250);

        OSCCONbits.IRCF0 = 0b0;
        OSCCONbits.IRCF1 = 0b0;
        OSCCONbits.IRCF2 = 0b0; // 31 khz

        while(BusyXLCD());
	putrsXLCD("Lcd Testando..");
        Delay10KTCYx(2);

         /* Set DDRam address to 0x40 to display data in the second line */
        SetDDRamAddr(0x40);
        putrsXLCD(data);

        Delay10KTCYx(2);
        OSCCONbits.IRCF0 = 0b0;
        OSCCONbits.IRCF1 = 0b0;
        OSCCONbits.IRCF2 = 0b1; // 1 mhz
        Delay10KTCYx(1000);
        }

}
Пример #7
0
void interrupt Interrupcao(void){

    char buffer[4];
    /* a string buffer ira guardar um numero decimal (0 a 32) traduzido pela
     * funcao itoa, onde ira transformar o numero inteiro em string com apontador
     * o tamanho poderia ser 3, mas o inteiro vai ate 3 posicoes + null
     *
     * the buffer string variable will hold a decimal number (0 to 32) that was
     * converted by the itoa function, changing a integer number into a string
     * pointer
     * its size could be only 3, but the interger goes up to 3 positions + null end
     */


    // LED_VERMELHO = ~LED_VERMELHO;
    // muda o status do LED_VERMELHO quando a MCU entrar em interrupcao
    // changes the LED_VERMELHO when the MCU interrupts

    // BUZZ=1; Delay100TCYx(10); BUZZ=0;
    // toca o buzzer para cada interrupcao
    // plays the buzzer for each interrupt

    if (RCIF)   // se existe interrupcao aguardando...
                // teoricamente este RCIF nao precisaria de verificacao
                // pois se a rotina de Interrupcao ja foi chamada, entao
                // nem seria necessario verifica-la
                // mas os LED1 e LED_VERMELHO servem justamente para comprovar
                // que o RCIF sempre ira existir, quando mudam juntos (leds)

                // Theoretically this RCIF "if" check should never be necessary
                // but just to confirm the RCIF, the two leds (LED1 and
                // LED_VERMELHO) will always change together.
        {

        RCIE = 0;   // desabilita interrupts de RX para tratar a entrada
                    // disables RX interrupts to treat input

        LED1 = ~LED1;
        // muda o status do primeiro LED
        // inverts the LED1 status

        chRX = ReadUSART();
        // le caractere da Serial / read a character from Serial

        if ( chRX>31 && chRX<127 && !BOTAO)
            // filtra apenas os caracteres texto comuns
            // just filter the common readable text characters
        {

            // Se o Echo Serial esta ativo, entao imprima o caractere na Serial
            // If Serial Echo is on, then send the character to Serial Port
            if (SerialEcho)
                {
                    while (BusyUSART()); // espera nao ocupado / waits non busy
                    WriteUSART(chRX);    // envia caractere na Porta Serial
                                         // sends the character in Serial Port
                }

            // Se o LcdDisplay esta ativo, entao imprima o caractere
            // If Lcd Display is enabled, print the character in LCD
            if (LcdDisplay)
            {
                while (BusyXLCD());
                WriteDataXLCD(chRX);

                contadorDisplay++;      // contador de caracteres para tabular
                                        // LCD character tabulation count
                if (contadorDisplay==16)    // se chegar ao final da primeira linha
                                            // if reaches the end of first line
                {
                    SetDDRamAddr(0x40); // comando para pular para segunda linha
                                        // command for going to second line
                    if (SerialEcho)
                    {
                        while (BusyUSART());
                        putrsUSART("\r\n"); // imprime RETURN e NEWLINE (inicio)
                                            // prints Carriage RETURN and Newline
                    }

                }

                if (contadorDisplay==32)    // se chegar ao final da segunda linha
                                            // if reaches the end of second line
                {
                    SetDDRamAddr(0x00);     // pula novamente para primeira linha
                                            // go again to first line
                    contadorDisplay=0;  // ja na primeira linha, limpa contador
                                        // in first line, clear the char counter
                    if (SerialEcho)
                    {
                        while (BusyUSART());
                        putrsUSART("\r\n"); // imprime RETURN e NEWLINE (inicio)
                                            // prints Carriage RETURN and Newline
                    }
                }

            }



        }
        else            // filtra todos demais Controls e Caracteres Especiais
                        // this is the state of non-text characters being filtered

        if (BOTAO)  // se o BOTAO de debug estiver pressionado, nao filtra controle
                    //if pushBOTTON is pressed, do not filter control characters
        {
                    while (BusyUSART());
                    WriteUSART(chRX);
        }
        else
        switch (chRX)
        {
            case 0x05 :      // Caractere ^E
                SerialEcho=!SerialEcho;
                while(BusyUSART());
                putrsUSART("\r\n[ECHO ");
                if (SerialEcho) putrsUSART("ON]"); else putrsUSART("OFF]");
                break;
                /*
                 * Control-E:
                 * Rotina para ligar e desligar o ECHO na porta serial
                 * Routine to turn on and off the ECHO in serial port
                 */

            case 0x10 :      // Caractere ^P
                LcdDisplay=!LcdDisplay;
                while(BusyUSART());
                putrsUSART("\r\n[LCD ");
                if (LcdDisplay) putrsUSART("ON]"); else putrsUSART("OFF]");
                break;
                /*
                 * Contro-P:
                 * Rotina para ligar e desligar a amostragem de Caractere no LCD
                 * Routine to turn on and off the display of characters in LCD
                 */

            case 0x0C :     // Caractere ^L (FormFeed)
                putrsUSART("\r\n[LCD CLS]");
                while(BusyXLCD());
                WriteCmdXLCD(0x01); // Comando para limpar o LCD
                contadorDisplay=0;
                break;
                /*
                 * Control-L: (LimpaTela / FormFeed)
                 * Rotina para Limpar a Tela
                 * Routine to CLear Screen (CLS)
                 */

            case 0x13 :     // Caractere ^S
                putrsUSART("\r\n[Status Lcd:");
                if (LcdDisplay) putrsUSART("On"); else putrsUSART("Off");
                putrsUSART(" Echo:");
                if (SerialEcho) putrsUSART("On"); else putrsUSART("Off");
                putrsUSART(" charLCD:");
                
                itoa ( buffer, contadorDisplay, 10);
                // itoa necessita da biblioteca <stdlib.h>
                // itoa needs the include stdlib.h
                putrsUSART( buffer );
                putrsUSART("]\r\n");
                /*
                 * Control-S:
                 * Mostra o Status do Echo, do LCD, e da quantidade de caracteres
                 * no LCD
                 * Shows the Status of Echo, LCD and characteres number in LCD
                 */
                
                break;

            default:
               
                ;
        }

        




        // two Peripheral Interrupt Request (Flag) registers (PIR1 and PIR2)
        // RCIF: EUSART Receive Interrupt Flag bit

        //PIR1bits.RCIF = 0; // PIR1 no registro RCIF
        RCIE = 1; // Re-Habilita a Interrupcao de Recepcao
                  // Re-Enable RX Interrupts

        RCIF = 0; // PIR1 no registro RCIF
        // limpa o registrador de interrupcao, e sai da interrupcao
        // clear the interrupt register, and quits it

        }
}