Пример #1
0
void lcd_draw_string(int x, int y, char *str) {
	printf("lcd draw string: %s\n", str);
	unsigned char cmd[3] = { 0xDB, 0, 0 };
	cmd[2] = x;
	cmd[1] = y;
	lcd_send_data(cmd, 3);
	lcd_send_data((unsigned char*)str, strlen(str));
	lcd_send_byte('\0');
	lcd_delay();
	return;
	
	int i = 0;
	while (*str != '\0') {
	    lcd_send_data((unsigned char *)str, 1);
	    ++str;
	    ++i;
	    if (i % 16 == 0 && *str != '\0') {
	        lcd_send_byte('\0');
	        usleep(1000);
	        cmd[2] = (x+i)*5;
	        lcd_send_data(cmd, 3);
	    }
	}
	lcd_send_byte('\0');
	lcd_delay();
}
Пример #2
0
void lcd_putc( char c) {
   switch (c) {
     case '\f'   : lcd_send_byte(0,1);
                   delay_ms(2);
                                           break;
     case '\n'   : lcd_gotoxy(1,2);        break;
     case '\b'   : lcd_send_byte(0,0x10);  break;
     default     : lcd_send_byte(1,c);     break;
   }
}
Пример #3
0
int _user_putc (char c){
   switch (c)
   {
      case '\a'   :  lcd_gotoxy(1,1);     break;
      case '\f'   :  
                     lcd_send_byte(0,1);
                     LCD_DELAY_F();
                     break;
      case '\n'   : lcd_gotoxy(1,2);        break;
      case '\b'   : lcd_send_byte(0,0x10);  break;
      default     : lcd_send_byte(1,c);     break;
   }
   return c;
}
Пример #4
0
void lcd_init(void) 
{
   BYTE i;

 #if defined(__PCB__)
   set_tris_lcd(LCD_OUTPUT_MAP);
 #else
  #if (defined(LCD_DATA4) && defined(LCD_DATA5) && defined(LCD_DATA6) && defined(LCD_DATA7))
   output_drive(LCD_DATA4);
   output_drive(LCD_DATA5);
   output_drive(LCD_DATA6);
   output_drive(LCD_DATA7);
  #else
   lcdtris.data = 0x0;
  #endif
   lcd_enable_tris();
   lcd_rs_tris();
   lcd_rw_tris();
 #endif

   lcd_output_rs(0);
   lcd_output_rw(0);
   lcd_output_enable(0);
    
   delay_ms(15);
   for(i=1;i<=3;++i)
   {
       lcd_send_nibble(3);
       delay_ms(5);
   }
    
   lcd_send_nibble(2);
   for(i=0;i<=3;++i)
      lcd_send_byte(0,LCD_INIT_STRING[i]);
}
Пример #5
0
void Initialize_LCD(void){
	int8 i;

	TRIS_RS=0;
	TRIS_E=0;


	RS_PIN=0;
	E_PIN=0;


	TRIS_DATA_PIN_4=0;
	TRIS_DATA_PIN_5=0;
	TRIS_DATA_PIN_6=0;
	TRIS_DATA_PIN_7=0;

	_delay_5ms();//15ms
	_delay_5ms();
	_delay_5ms();

	for(i=0 ;i < 3; i++){
		lcd_send_nibble(0x03);
		_delay_5ms();//5ms
  	}

	lcd_send_nibble(0x02);

	for(i=0; i < sizeof(LCD_INIT_STRING); i++){
		lcd_send_byte(0, LCD_INIT_STRING[i]);

	}
}
Пример #6
0
void dsp_set_cgram_address( int8 which, int8 line ) {
	which <<= 3;
	which &= 0x38;		//Begin of glyph
	which |= line;		//Position in glyph

	lcd_send_byte(0, 0x40 | which);  //set cgram address
}
Пример #7
0
void lcd_gotoxy(int8 x, int8 y) 
{ 
int8 address; 


switch(y) 
  { 
   case 1: 
     address = LCD_LINE_1_ADDRESS; 
     break; 

   case 2: 
     address = LCD_LINE_2_ADDRESS; 
     break; 

   case 3: 
     address = LCD_LINE_3_ADDRESS; 
     break; 

   case 4: 
     address = LCD_LINE_4_ADDRESS; 
     break; 

   default: 
     address = LCD_LINE_1_ADDRESS; 
     break; 
      
  } 

address += x-1; 
lcd_send_byte(0, 0x80 | address); 
} 
Пример #8
0
void lcd_send_data(uint8_t data)
{
	RS_OUT;
	RW_OUT;
	SET_RS;
	CLR_RW;
	lcd_send_byte(data);
}
Пример #9
0
void lcd_send_cmd(uint8_t cmd)
{
	RS_OUT;
	RW_OUT;
	CLR_RS;
	CLR_RW;
	lcd_send_byte(cmd);
}
void lcd_gotoxy( BYTE x, BYTE y) {
   BYTE address;

   // sans control
   address = taddrLines[y];
   
   address+=x-1;
   lcd_send_byte(0,0x80|address);
}
Пример #11
0
void lcd_gotoxy( byte x, byte y) {
   byte address;

   if(y!=1)
     address=lcd_line_two;
   else
     address=0;
   address+=x-1;
   lcd_send_byte(0,0x80|address);
}
Пример #12
0
void lcd_gotoxy( BYTE x, BYTE y) {
   BYTE address;

   if(y!=1)
     address=lcd_line_two;
   else
     address=0;
   address+=x-1;
   lcd_send_byte(0,0x80|address);
}
Пример #13
0
//----------------------------
void lcd_gotoxy(int8 x, int8 y){
	int8 address;

	if(y != 1)
		address = lcd_line_two;
	else
		address=0;

	address += x-1;
	lcd_send_byte(0, 0x80 | address);
}
Пример #14
0
void lcd_gotoxy(unsigned char x, unsigned char y){
   unsigned char address;

   if(y!=1)
      address = lcd_line_two;
   else
      address = 0;

   address += x-1;
   lcd_send_byte(0,0x80|address);
}
Пример #15
0
void lcd_gotoxy(BYTE x, BYTE y)
{
   BYTE address;

   if(y!=1)
      address=LCD_LINE_TWO;
   else
      address=0;
     
   address+=x-1;
   lcd_send_byte(0,0x80|address);
}
Пример #16
0
void lcd_gotoxy(int8 x, int8 y) 
{ 
   int8 address; 
    
   if(y != 1) 
      address = LCD_LINE_TWO; 
   else 
      address=0; 
    
   address += x-1; 
   lcd_send_byte(0, 0x80 | address); 
} 
Пример #17
0
void lcd_write_data(unsigned char data)
{	
    OS_CPU_SR_ALLOC();
    

    OS_ENTER_CRITICAL();
    
    LCD_RS_HIGH();
    LCD_CS_LOW();
    lcd_send_byte(data);
    LCD_CS_HIGH();

    OS_EXIT_CRITICAL();
}
Пример #18
0
void lcd_write_cmd(unsigned char cmd)
{   
    OS_CPU_SR_ALLOC();
    

    OS_ENTER_CRITICAL();
    
    LCD_RS_LOW();
    LCD_CS_LOW();
    lcd_send_byte(cmd);
    LCD_CS_HIGH();

    OS_EXIT_CRITICAL();
}
void lcd_init() {
    BYTE i;
    set_tris_lcd(LCD_WRITE);
    lcd.rs = 0;
    lcd.rw = 0;
    lcd.enable = 0;
    delay_ms(15);
    for(i=1;i<=3;++i) {
       lcd_send_nibble(3);
       delay_ms(5);
    }
    lcd_send_nibble(2);
    for(i=0;i<=3;++i)
       lcd_send_byte(0,LCD_INIT_STRING[i]);
}
Пример #20
0
void lcd_init(void) 
{ 
int8 i; 

lcd_line = 1; 

output_low(LCD_RS); 

#ifdef USE_RW_PIN 
output_low(LCD_RW); 
#endif 

output_low(LCD_E); 

// Some LCDs require 15 ms minimum delay after 
// power-up.  Others require 30 ms.  I'm going 
// to set it to 35 ms, so it should work with 
// all of them. 
delay_ms(35);          

for(i=0 ;i < 3; i++) 
   { 
    lcd_send_nibble(0x03); 
    delay_ms(5); 
   } 

lcd_send_nibble(0x02); 

for(i=0; i < sizeof(LCD_INIT_STRING); i++) 
   { 
    lcd_send_byte(0, LCD_INIT_STRING[i]); 
    
    // If the R/W signal is not used, then 
    // the busy bit can't be polled.  One of 
    // the init commands takes longer than 
    // the hard-coded delay of 50 us, so in 
    // that case, lets just do a 5 ms delay 
    // after all four of them. 
    #ifndef USE_RW_PIN 
    delay_ms(5); 
    #endif 
   } 

} 
Пример #21
0
//---------------------------- 
void lcd_init(void) 
{ 
	char i; 
	
	output_low(LCD_RS); 
	
	#ifdef USE_LCD_RW 
	output_low(LCD_RW); 
	#endif 
	
	output_low(LCD_E); 
	
	delay_ms(15); 
	
	for(i=0 ;i < 3; i++) 
	{ 
		lcd_send_nibble(0x03); 
		delay_ms(5); 
	}
	
	lcd_send_nibble(0x02); 
	
	for(i=0; i < sizeof(LCD_INIT_STRING); i++) 
   { 
    lcd_send_byte(0, LCD_INIT_STRING[i]); 
    
    // If the R/W signal is not used, then 
    // the busy bit can't be polled.  One of 
    // the init commands takes longer than 
    // the hard-coded delay of 60 us, so in 
    // that case, lets just do a 5 ms delay 
    // after all four of them. 
    #ifndef USE_LCD_RW 
    delay_ms(5); 
    #endif 
   } 

} 
Пример #22
0
void lcd_init(void){
	int8 i;

	TRISRS=0;
	TRISEN=0;
#ifdef USE_RW
	TRISRW=0;
#endif

	RSPIN=0;
	EPIN=0;
#ifdef USE_RW
	RWPIN=0;
#endif

	TRIS_DATA_PIN_4=0;
	TRIS_DATA_PIN_5=0;
	TRIS_DATA_PIN_6=0;
	TRIS_DATA_PIN_7=0;

	_delay_5ms();//15ms
	_delay_5ms();
	_delay_5ms();

	for(i=0 ;i < 3; i++){
		lcd_send_nibble(0x03);
		_delay_5ms();//5ms
  	}

	lcd_send_nibble(0x02);

	for(i=0; i < sizeof(LCD_INIT_STRING); i++){
		lcd_send_byte(0, LCD_INIT_STRING[i]);
	#ifndef USE_RW
		_delay_5ms();
	#endif
	}
}
Пример #23
0
void dsp_strength_bar( int8 end_signal_char_index,
						int8 width, int8 value ) 
{
	int8 mark_pos = value/STRENGTH_VALUES_PER_CHAR;
	int8 mark_glyph = value-(mark_pos*STRENGTH_VALUES_PER_CHAR);
	
	lcd_output_rs(0);
	int8 current_address = lcd_read_byte() & 0x7F;
	
	dsp_create_signal_character( end_signal_char_index, mark_glyph );
	
	lcd_send_byte( 0, 0x80|current_address );	//Restore DDRAM address
	
	int8 i;
	for( i=0; i<mark_pos; ++i ) {
		lcd_putc(CHAR_FULL_STRENGTH);
	}
	if ( mark_pos != width ) {
		lcd_putc(end_signal_char_index);
	}
	for( i=mark_pos+1; i<width; ++i ) {
		lcd_putc(' ');
	}
}
Пример #24
0
void lcd_init(void) 
{ 
   int8 i; 

   output_low(LCD_RS); 
   output_low(LCD_E); 

   delay_ms(15); 

   for(i=0 ;i < 3; i++) 
   { 
      lcd_send_nibble(0x03); 
      delay_ms(5); 
   } 

   lcd_send_nibble(0x02); 

   for(i=0; i < sizeof(LCD_INIT_STRING); i++) 
     { 
       lcd_send_byte(0, LCD_INIT_STRING[i]); 
       
       delay_ms(5); 
   } 
} 
Пример #25
0
void main()
{

TRISC=0;
// Variables para controlador
int16 valor;     
float control;                //valor del PWM
float a1,b1,c1;                  //constantes del PID
float ref;            //temperatura a alcanzar
float rT,eT,iT,dT,yT,uT,iT0,eT0,iT_1,eT_1;     //variables de ecuaciones            
float max,min;               //límites máximo y mínimo de control.
float T ,Kp1, Ti1,Td1;  


setup_adc_ports(RA0_ANALOG);//entrada del LM35
setup_adc(ADC_CLOCK_INTERNAL);
setup_COUNTERS(RTCC_internal.rtcc_div_1);
set_adc_channel(0);

  setup_timer_2(t2_div_by_4,500,1);     //periodo de la señal PWM a 1ms
setup_ccp1(ccp_pwm);                  //Módulo CCP a modo PWM
setup_adc(ADC_CLOCK_INTERNAL);       //reloj convertidor AD interno
set_adc_channel(0);

setup_timer_0(rtcc_ext_l_to_h|RTCC_DIV_2);   //Configuración TMR0
setup_timer_1(T1_internal|T1_DIV_BY_8);     //Configuración TMR1

  float Temp;
  int c;
  char k;
  char Kp[6];
  char Ki[6];
  char Kd[6];
  char Sp[6];
  int v;
  
   port_b_pullups(true),
   lcd_init();
   kbd_init();
   
   
   inicio:
   
   for (v=0;v<=5;v++){
   Kp[v]=0; Ki[v]=0; Kd[v]=0; Sp[v]=0;
   }
   
   lcd_gotoxy(1,1);
   lcd_putc("\f");
   lcd_putc("Kp:");
   lcd_gotoxy(9,1);
   lcd_putc("Ki:");
   lcd_gotoxy(1,2);
   lcd_putc("Kd:");
   lcd_gotoxy(9,2);
   lcd_putc("Sp:");
   
   while(true){
      K_p:
      lcd_gotoxy(4,1);
      lcd_send_byte(0,0x0f);
      c=0;
      k=0;
      while(c<=4){
      
      k=kbd_getc();
      if(k!=0){
      
         
        
         if(k!='A' && k!='*' && k!='C'){
            
            if(k=='B'){
               printf(lcd_putc,".");
               Kp[c]=k;
               lcd_gotoxy(4+c,1);      
            }
            else
            printf(lcd_putc,"%c",k);
            Kp[c]=k;
            lcd_gotoxy(4+c,1);            
                
         }
         
         if(k=='A'){
               c++;
               Kp[c]=-92;                
               lcd_gotoxy(4+c,1);
                  
          }
               
          
      }
      if(k=='D'){
         int j=0;
         for(;;){
            Kp[j]=0;
            if(j==5) break;
            j++;
         }
      c=0;
      lcd_gotoxy(1,1);
      lcd_putc("Kp:     ");
      lcd_gotoxy(4+c,1);
      
      }
      if(k=='*'){
            Kp[c+1]=-92;
            
            goto K_i;  
           
          }
      
      
      }  //FUERA DEL WHILE
      
      lcd_gotoxy(4+c-1,1);
      lcd_send_byte(0,0x0f);
      k=0;
      
      for(;;){
         k=kbd_getc();
         if(k!=0){
            if(k=='*'){
               break;
             }          
         }
      }
    
      
      K_i:
      lcd_gotoxy(12,1);
      lcd_send_byte(0,0x0f);
      c=0;
      k=0;
      
      ///KI
      while(c<=4){
      
      k=kbd_getc();
      if(k!=0){
      
         
        
         if(k!='A' && k!='*'){
            
            if(k=='B'){
               printf(lcd_putc,".");
               Ki[c]=k;
               lcd_gotoxy(12+c,1);      
            }
            else
            printf(lcd_putc,"%c",k);
            Ki[c]=k;
            lcd_gotoxy(12+c,1);            
                
         }
         
         if(k=='A'){
               c++; 
               Ki[c]=-92; 
               lcd_gotoxy(12+c,1);
                  
          }
          
          
          
      }
      if(k=='D'){
         int j=0;
         for(;;){
            Ki[j]=0;
            if(j==5) break;
            j++;
         }
      c=0;
      lcd_gotoxy(9,1);
      lcd_putc("Ki:      ");
      lcd_gotoxy(12+c,1);
      }
      
      if(k=='*'){
         Ki[c+1]=-92; 
         goto K_d;  
      }      
      }
     
      ///FIN KI 
      ///FUERA DEL WHILE
      lcd_gotoxy(12+c-1,1);
      lcd_send_byte(0,0x0f);
      k=0;
      
      for(;;){
         k=kbd_getc();
         if(k!=0){
            if(k=='*'){
               break;
             }          
         }
      }
      
      K_d:
      lcd_gotoxy(4,2);
      lcd_send_byte(0,0x0f);
      c=0;
      k=0;
      
      while(c<=4){
      
      k=kbd_getc();
      if(k!=0){
      
         
        
         if(k!='A' && k!='*'){
            
            if(k=='B'){
               printf(lcd_putc,".");
               Kd[c]=k;
               lcd_gotoxy(4+c,2);      
            }
            else
            printf(lcd_putc,"%c",k);
            Kd[c]=k;
            lcd_gotoxy(4+c,2);            
                
         }
         
         if(k=='A'){
               c++; 
               Kd[c]=-92;
               lcd_gotoxy(4+c,2);
                  
          }
          
          
          
      }
      if(k=='D'){
         int j=0;
         for(;;){
            Kd[j]=0;
            if(j==5) break;
            j++;
         }
      c=0; 
      lcd_gotoxy(1,2);
      lcd_putc("Kd:     ");
      lcd_gotoxy(4+c,2);
      }
      
      if(k=='*'){
         Kd[c+1]=-92;
         goto S_p;  
      }      
      }
      //FUERA WHILE
      lcd_gotoxy(4+c-1,2);
      lcd_send_byte(0,0x0f);
      k=0;
      
      for(;;){
         k=kbd_getc();
         if(k!=0){
            if(k=='*'){
               break;
             }          
         }
      }
      
      ///SP
      S_p:
      lcd_gotoxy(12,2);
      lcd_send_byte(0,0x0f);
      c=0;
      k=0;
      while(c<=4){
      
      k=kbd_getc();
      if(k!=0){
      
         
        
         if(k!='A' && k!='*'){
            
            if(k=='B'){
               printf(lcd_putc,".");
               Sp[c]=k;
               lcd_gotoxy(12+c,2);      
            }
            else
            printf(lcd_putc,"%c",k);
            Sp[c]=k;
            lcd_gotoxy(12+c,2);            
                
         }
         
         if(k=='A'){
               c++; 
               Sp[c]=-92;
               lcd_gotoxy(12+c,2);
                  
          }
          
          
          
      }
      if(k=='D'){
         int j=0;
         for(;;){
            Sp[j]=0;
            if(j==5) break;
            j++;
         }
      c=0; 
      lcd_gotoxy(9,4);
      lcd_putc("Sp:     ");
      lcd_gotoxy(12+c,2);
      }
      if(k=='*'){
         Sp[c+1]=-92;
         goto PID;  
      }      
      }
      
      lcd_gotoxy(12+c-1,2);
      lcd_send_byte(0,0x0f);
      k=0;
      
      for(;;){
         k=kbd_getc();
         if(k!=0){
            if(k=='*'){
               break;
             }          
         }
      }
          
      PID:
      
      printf(lcd_putc, "\f");             // Borra la pantalla
    lcd_gotoxy(4, 1);
    printf(lcd_putc, "procesando.. ");
    delay_ms(600);
    
      float result;
       a1 = conv(Kp); b1 = conv(Ki);c1 = conv(Kd);ref = conv(Sp);
      
     // strtod(cc,NULL);
      lcd_init();
      iT0=0.0;
      eT0=0.0;
      min=0.0;   //inicialización variables
      uT = 0.0;
      max=1023;
      while(True){
      Temp=(float)read_adc();
      
      yT=Temp*5.0/1024.0; 
      
      
      rT=ref;                    
      eT=rT-yT;   //Cálculo error
      lcd_gotoxy(1,2);
      printf(lcd_putc,"error:%f",eT);
      
      iT=b1*eT+iT0;                         //Cálculo del término integral
      dT=c1*(eT-eT0);                       //Cálculo del término derivativo 
      
      uT=iT+a1*eT+dT;     //Cálculo de la salida PID
      lcd_gotoxy(1,1);
      printf(lcd_putc,"Out:%f",uT);
      
 
      if (uT>max) {        //Salida PID si es mayor que el MAX
          uT=max;}                          
      else {
      if (uT<min){      //Salida PID si es menor que el MIN 
            uT=min;}                           
         }                             


      
       control=uT;  //Transferencia de salida PID a señal PWM
      lcd_gotoxy(10,1);
      printf(lcd_putc,"Sp:%f",ref);
       
       set_pwm1_duty(control);
       iT0=iT;                        //Guardar variables
       eT0=eT;
       
                                                                
   
      delay_ms(20);

      }
      
      

      
   }
   }
Пример #26
0
void lcd_reset() {
	lcd_send_byte(0xEF);
	sleep(1);
}
Пример #27
0
void dsp_create_signal_character( int8 which, int8 strength ) {
	dsp_set_cgram_address( which, 2 );
	
	for( int8 i=0; i<3; i++ )
	   lcd_send_byte(1, CHAR_SIGNAL_STRENGTH_GLYPH[strength]);
}
Пример #28
0
void dsp_write_mid_glyph( int8 which, int8 *ptr ) {
	dsp_set_cgram_address( which, 2 );

	for( int8 i=0; i<3; i++ )
	   lcd_send_byte(1, *ptr++);
}
Пример #29
0
/*
 * Display a range bar with:
 *	- 3 possibles values per position in mid characters
 *	- 2 possibles values per position in start and end characters
 * Note: Only one range line is allowed.
 */
void dsp_range_line( int8 start_char_index, 
					int8 mid_char_index, 
					int8 end_char_index, 
					int8 width, int16 value, 
					int16 max_value ) 
{
	int8 range_positions = (3*(width-2)) + 2 + 2;
	int8 mark = math_change_range(value, max_value, range_positions);
	
	int8 start_glyph;
	int8 end_glyph;
	int8 mark_glyph;
	int8 mark_pos;
	if ( mark < 2 ) {							//Mark at start range
		mark_pos = 0;
		mark_glyph = 0xFF;
		start_glyph = mark;
		end_glyph = 2;
	}
	else if ( mark > (range_positions-2) ) {	//Mark at end range
		mark_pos = 0;
		mark_glyph = 0xFF;
		start_glyph = 2;
		end_glyph = (range_positions-mark);
	}
	else if ( mark == (range_positions-2) ) {	//Mark just before end range
		mark_pos = 0;
		mark_glyph = 0xFF;
		start_glyph = 2;
		end_glyph = 1;
	}
	else {										//Mark at mid range
		mark -= 2;
		mark_pos = mark/3;
		mark_glyph = mark-(mark_pos*3);
		start_glyph = 2;
		end_glyph = 2;
	}
	
	lcd_output_rs(0);
	int8 current_address = lcd_read_byte() & 0x7F;
	
				// Set glyphs
	dsp_write_mid_glyph( start_char_index, 
								CHAR_START_RANGE_MID_GLYPH[start_glyph] );
	dsp_write_mid_glyph( end_char_index, 
								CHAR_END_RANGE_MID_GLYPH[end_glyph] );
	if ( mark_glyph != 0xFF ) {
		dsp_write_mid_glyph( mid_char_index, 
									CHAR_RANGE_POSITION_GLYPH[mark_glyph] );
	}
	
	lcd_send_byte( 0, 0x80|current_address );	//Restore DDRAM address
	
				// Write range line
	int8 i;
	lcd_putc(start_char_index);
	for( i=0; i<mark_pos; ++i ) {
		lcd_putc('-');
	}
	lcd_putc( (mark_glyph==0xFF) ? '-' : mid_char_index);
	for( i=mark_pos+1; i<(width-2); ++i ) {
		lcd_putc('-');
	}
	lcd_putc(end_char_index);
}
Пример #30
0
void dsp_clear_character( int8 which ) {
	dsp_set_cgram_address( which, 0 );
	for( int8 i=0; i<8; i++ )
	   lcd_send_byte(1, 0);
}