Ejemplo n.º 1
0
//! Receive a long.
unsigned long rxlong() {
    unsigned long toret=0;
    toret=serial_rx();
    toret|=(((long)serial_rx())<<8);
    toret|=(((long)serial_rx())<<16);
    toret|=(((long)serial_rx())<<24);
    return toret;
}
Ejemplo n.º 2
0
static void imx_rxint(struct imx_port *port)
{
	while (imx_lowlevel_can_getc(port->base)) {
		u8 ch = imx_lowlevel_getc(port->base);
		serial_rx(port->p, &ch, 1);
	}
}
Ejemplo n.º 3
0
static vmm_irq_return_t omap_uart_irq_handler(int irq_no, void *dev)
{
	u16 iir, lsr;
	struct omap_uart_port *port = (struct omap_uart_port *)dev;

        iir = omap_serial_in(port, UART_IIR);
        if (iir & UART_IIR_NO_INT)
                return VMM_IRQ_NONE;

        lsr = omap_serial_in(port, UART_LSR);

	/* Handle RX FIFO not empty */
         if (iir & (UART_IIR_RLSI | UART_IIR_RTO | UART_IIR_RDI)) {
		if (lsr & UART_LSR_DR) {
			do {
				u8 ch = omap_serial_in(port, UART_RBR);
				serial_rx(port->p, &ch, 1);
			} while (omap_serial_in(port, UART_LSR) &
					      (UART_LSR_DR | UART_LSR_OE));
		} else if (lsr & (UART_LSR_OE | \
				  UART_LSR_PE | \
				  UART_LSR_BI | UART_LSR_FE) ) {
			while (1);
		}
        }

	omap_serial_out(port, UART_IER, port->ier);

	return VMM_IRQ_HANDLED;
}
Ejemplo n.º 4
0
int main(int argc, char ** argv) {
    int error;
    int cnt = 0;
    int ind;
    char* teststr = "cutaway\n\0";
     
    error = setup_serial();
    if (error < 0){
        printf("serial setup error\n");
        return -1;
    }

    while (cnt < strlen(teststr)){
        //serputc(teststr[cnt],ser_fd);
        serial_tx(teststr[cnt],ser_fd);
        cnt++;
    }
    
    //ind = sergetc(ser_fd);
    ind = serial_rx(ser_fd);
    printf("sergetc\n");
    printf("decimal incoming: %d\n",ind);
    printf("char incoming: %c\n",(char)ind);
    
    // Don't forget to clean up
    close(ser_fd);
    return 0;
}
Ejemplo n.º 5
0
void nmea_rx_update(void)
{
	/* update nmea buffer */
	while (serial_rx_avail())
	{
		char c = serial_rx();
		if (c=='$') { /* start of message */
			if (rx_len != -1) {
				nmea_err++;
			}
			rx_len = 0;
		}
		else if (c==CHAR_CR || c==CHAR_LF) /* end of message */
		{
			if (rx_len >= 4) {
				if (nmea_rx_validate())
					nmea_rx_parse();
				else
				{
					nmea_err++; 
/* tx_inbuf(); */
				}
			}
			rx_len = -1; /* waiting for next start of message */
		}
		else if (rx_len != -1) {
			/* copy anything but $ and CR LF to the buffer */
			rx[rx_len++] = c;
			if (rx_len == RXBUF_SIZE) { /* buffer overflow error */
				rx_len = -1; /* waiting for next start of message */
				nmea_err++;
			}
		}
	}
}
Ejemplo n.º 6
0
static void uartTask(void* unused) {
   dn_error_t           dnErr;
   INT8U                osErr;
   dn_uart_open_args_t  uartOpenArgs;
   INT32U               rxLen;
   INT32U               channelMsgType;
   INT32S               err;
   
   // create the memory block for the UART channel
   bridge_app_v.uartRxChannelMem = OSMemCreate(
      bridge_app_v.uartRxChannelMemBuf,
      1,
      sizeof(bridge_app_v.uartRxChannelMemBuf),
      &osErr
   );
   ASSERT(osErr==OS_ERR_NONE);
   
   // create an asynchronous notification channel
   dnErr = dn_createAsyncChannel(bridge_app_v.uartRxChannelMem, &bridge_app_v.uartRxChannel);
   ASSERT(dnErr==DN_ERR_NONE);
   
   // associate the channel descriptor with UART notifications
   dnErr = dn_registerChannel(bridge_app_v.uartRxChannel, DN_MSG_TYPE_UART_NOTIF);
   ASSERT(dnErr==DN_ERR_NONE);
   
   // open the UART device
   uartOpenArgs.rxChId    = bridge_app_v.uartRxChannel;
   uartOpenArgs.rate        = 115200u;
   uartOpenArgs.mode        = DN_UART_MODE_M4;
   uartOpenArgs.ctsOutVal   = 0;
   err = dn_open(
      DN_UART_DEV_ID,
      &uartOpenArgs,
      sizeof(uartOpenArgs)
   );
   ASSERT(err>=0);
   
   while(1) { // this is a task, it executes forever
      
      // wait for UART messages
      dnErr = dn_readAsyncMsg(
         bridge_app_v.uartRxChannel,   // chDesc
         bridge_app_v.uartRxBuffer,    // msg
         &rxLen,                       // rxLen
         &channelMsgType,              // msgType
         MAX_UART_PACKET_SIZE,         // maxLen
         0                             // timeout (0==never)
      );
      ASSERT(dnErr==DN_ERR_NONE);
      ASSERT(channelMsgType==DN_MSG_TYPE_UART_NOTIF);
      
      // call the callback
      serial_rx(bridge_app_v.uartRxBuffer,rxLen);
   }
}
Ejemplo n.º 7
0
//! Main loop.
int main(void)
{
  volatile unsigned int i;
  unsigned char app, verb, len;
  
  init();
  
  txstring(MONITOR,OK,"http://goodfet.sf.net/");
  
  //Command loop.  There's no end!
  while(1){
    //Magic 3
    app=serial_rx();
    verb=serial_rx();
    len=serial_rx();
    
    //Read data, if any
    for(i=0;i<len;i++){
      cmddata[i]=serial_rx();
    }
    handle(app,verb,len);
  }
}
Ejemplo n.º 8
0
static vmm_irq_return_t uart_8250_irq_handler(int irq_no, void *dev)
{
	u16 iir, lsr;
	struct uart_8250_port *port = (struct uart_8250_port *)dev;

        iir = uart_8250_in(port, UART_IIR_OFFSET);
        lsr = uart_8250_in(port, UART_LSR_OFFSET);

	switch (iir & 0xf) {
        case UART_IIR_NOINT:
		return VMM_IRQ_NONE;

	case UART_IIR_RLSI:
	case UART_IIR_RTO:
	case UART_IIR_RDI:
		if (lsr & UART_LSR_BRK_ERROR_BITS) {
			uart_8250_clear_errors(port);
		}
		if (lsr & UART_LSR_DR) {
			do {
				u8 ch = uart_8250_in(port, UART_RBR_OFFSET);
				serial_rx(port->p, &ch, 1);
			} while (uart_8250_in(port, UART_LSR_OFFSET) &
					      (UART_LSR_DR | UART_LSR_OE));
		} else {
			while (1);
		}
		break;

	case UART_IIR_BUSY:
		/* This is unallocated IIR value as per generic UART but is
		 * used by Designware UARTs, we do not expect other UART IPs
		 * to hit this case
		 */
		uart_8250_in(port, 0x1f);
		uart_8250_out(port, UART_LCR_OFFSET, port->lcr_last);
		break;
	default:
		break;
	};

	return VMM_IRQ_HANDLED;
}
Ejemplo n.º 9
0
int main(void)
{
	sched_init(); /* initialize the scheduler */
	RC_LED_INIT; /* initialize RoboCard LED */
	serial_init(); /* initialize serial communication */
	sched_cnt = 0;
	cnt_since_last = 0;	
	sei(); /* enable interrupts */

	for (;;) /* go into an endless loop */
	{
		if (sched_int != 0) /* if the scheduler interrupt has timed out */
		{
			sched_int--;
			cnt_since_last++;
			sched_cnt++;
			if (sched_cnt == 10000)
				sched_cnt = 0;

			if (sched_cnt % 5000 == 0) /* each 500 ms */
			{
				RC_LED_FLIP;
			}
		}
		if (serial_rx_avail())
		{
			c = serial_rx();
			if (c == '$')
			{	
				cnt_since_last_tmp = cnt_since_last;
				cnt_since_last = 0;
				
				if (cnt_since_last_tmp <= 250)
					c = cnt_since_last_tmp;
				else
					c = 251;
				serial_tx_direct (c);
			}
		}
	}
	return 0; /* just for the principle as we never get here */
}
Ejemplo n.º 10
0
static vmm_irq_return_t samsung_irq_handler(int irq_no, void *dev)
{
    u16 data;
    struct samsung_port *port = (struct samsung_port *)dev;

    /* Get masked interrupt status */
    data = vmm_in_le16((void *)(port->base + S3C64XX_UINTP));

    /* handle RX FIFO not empty */
    if (data & S3C64XX_UINTM_RXD_MSK) {
        /* Mask RX interrupts till RX FIFO is empty */
        while (samsung_lowlevel_can_getc(port->base)) {
            u8 ch = samsung_lowlevel_getc(port->base);
            serial_rx(port->p, &ch, 1);
        }
    }

    /* Clear all interrupts */
    vmm_out_le16((void *)(port->base + S3C64XX_UINTP), data);

    return VMM_IRQ_HANDLED;
}
Ejemplo n.º 11
0
//! Receive a word.
unsigned int rxword() {
    unsigned long toret=0;
    toret=serial_rx();
    toret|=(((long)serial_rx())<<8);
    return toret;
}
Ejemplo n.º 12
0
void main() {
  unsigned char i,tmp;

  CMCON=0x07; 
  TRISA=0x30;
  TRISB=0xE7;
  
  PORTA=0xFE;
  PORTB=0x00;

  lcd_init();

  i2c_init();
  
  serial_init();

//teste lcd
  lcd_cmd(L_CLR); 
  lcd_cmd(L_L1);
  for(i=0;i<16;i++)
  {
    lcd_dat('A'+i);
  }
  lcd_cmd(L_L2);
  for(i=0;i<16;i++)
  {
    lcd_dat('a'+i);
  }

  atraso_ms(200);
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+3);
  lcd_str("Teste LCD");
  
  for(i=32;i<128;i++)
  {
    if((i%16) == 0)lcd_cmd(L_L2);
    lcd_dat(i);
    atraso_ms(50);
  }

  atraso_ms(100);
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+3);
  lcd_str("Teste LCD");
  lcd_cmd(L_L2+7);
  lcd_str("Ok");
  atraso_ms(500);

//teste LEDS
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+1);
  lcd_str("Teste LEDs");
 
for(i=0;i<4;i++)
  {
    atraso_ms(100);
    RA1^=1;
    atraso_ms(100);
    RA2^=1;
    atraso_ms(100);
    PORTA^=0x40; //RA6=1;
    atraso_ms(100);
    PORTA^=0x80; //RA7=1;
    atraso_ms(100);
  }


//teste Teclado
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+2);
  lcd_str("Teste Teclado");

  lcd_cmd(L_L2+1);

  i=0;
  while(i<14)
  {
    lcd_dat(tc_tecla(3000)+0x30);
    i++;
  }

//teste EEPROM EXT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste EEPROM EXT");
// testar ? 
  lcd_cmd(L_L2);
  lcd_str("Testar (1/0) ?");
 
  if(tc_tecla(0) == 1)
  {
    tmp=e2pext_r(10);
    lcd_dat(tmp);

    e2pext_w(10,0xA5);
    e2pext_w(10,0x5A);
    i=e2pext_r(10);

    e2pext_w(10,tmp);

    lcd_cmd(L_CLR);
    lcd_cmd(L_L1);
    lcd_str("Teste EEPROM EXT");
    lcd_cmd(L_L2);
    if(i == 0x5A) 
      lcd_str("     OK");
    else
      lcd_str("     ERRO");

    atraso_ms(1000);
  }


//teste RTC
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste RTC");
  
//ajuste  rtc_w();

//  rtc_w();
 
  rtc_r();
  lcd_cmd(L_L2);
  lcd_str((char *)date);
   atraso_ms(1500);
  for(i=0;i<16;i++)
  {
    rtc_r();
    lcd_cmd(L_L2);;
    lcd_str((char *)time);
    atraso_ms(500); 
  }

   
   //teste serial
   
 //teste EEPROM EXT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Serial");
// testar ? 
  lcd_cmd(L_L2);
  lcd_str("Testar (1/0) ?");
  if(tc_tecla(0) == 1)
  {  
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Serial TX");
  lcd_cmd(L_L2+2);
  lcd_str("9600 8N1");

  serial_tx_str("\r\n Picsimlab\r\n Teste Serial TX\r\n");

  for(i=0;i<4;i++)
  {
    serial_tx(i+0x30);
    serial_tx_str(" PicsimLab\r\n");
  }
  atraso_ms(1000);

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Serial RX");
  serial_tx_str(" Digite!\r\n");
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
       lcd_cmd(L_L2);
       serial_tx_str("\r\n");
    }
    tmp=serial_rx(3000);
    lcd_dat(tmp);
    serial_tx(tmp);
  }
  atraso_ms(100);
  
  
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Teclado TX");
  serial_tx_str("\r\n Aguarde!\r\n");
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
      lcd_cmd(L_L2);
      serial_tx_str("\r\n");
    }
    tmp=tc_tecla(2000)+0x30;
    lcd_dat(tmp);
    serial_tx(tmp);
  }
  atraso_ms(100);
  }

//fim teste 
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+4);
  lcd_str("Fim");
  lcd_cmd(L_L2+1);
  lcd_str("Pressione RST");

  serial_tx_str("\r\n FIM!\r\n");  

  while(1);


}
Ejemplo n.º 13
0
void main() {
    byte SERVO_0 = 0, SERVO_1 = 0;
    byte MOTOR_L = 0, MOTOR_R = 0, MOTOR_V = 0;
    short BUCKET_L = 0, BUCKET_R = 0, BUCKET_V = 0;
    byte T = 0;
    
    init();
    
    while (1) {
        byte cmd = serial_rx();
        byte power, s0, s1;
        
        switch (cmd) {
            case CMD_SET_MOTORS :
                MOTOR_L = serial_rx();
                MOTOR_R = serial_rx();
                MOTOR_V = serial_rx();
                
                s0 = serial_rx();
                s1 = serial_rx();
                
                set_servo(1 << 0, SERVO_0);
                set_servo(1 << 1, SERVO_1);
                
                SERVO_0 = s0;
                SERVO_1 = s1;
                
                // read temperature data from RE2 (ANS7)
                serial_tx(read_analog(7));
                break;
        }
        
        BUCKET_L += MOTOR_L - 127;
        BUCKET_R += MOTOR_R - 127;
        BUCKET_V += MOTOR_V - 127;
        
        power = 0;
        
        if (BUCKET_L >= 127) {
            BUCKET_L -= 127;
            power = power | (1 << 0);
        }
        else if (BUCKET_L < -127) {
            BUCKET_L += 127;
            power = power | (1 << 1);
        }
        
        if (BUCKET_R >= 127) {
            BUCKET_R -= 127;
            power = power | (1 << 2);
        }
        else if (BUCKET_R < -127) {
            BUCKET_R += 127;
            power = power | (1 << 3);
        }
        
        if (BUCKET_V >= 127) {
            BUCKET_V -= 127;
            power = power | (1 << 4);
        }
        else if (BUCKET_V < -127) {
            BUCKET_V += 127;
            power = power | (1 << 5);
        }
        
        PORTA = power;
        wait_msec(4);
    }
}
Ejemplo n.º 14
0
void main() 
{
  unsigned char i;
  unsigned char tmp;
  unsigned int tmpi;

  char str[6];

  ADCON1=0x06;
  TRISA=0xFF;
  TRISB=0x00;
  TRISC=0x01;
  TRISD=0x00;
  TRISE=0x00;

  lcd_init();
  i2c_init();
  serial_init();
  adc_init();

//testa caracter especial
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste LCD"));

  lcd_cmd(0x40);//endereço

  lcd_dat(0x11);
  lcd_dat(0x19);
  lcd_dat(0x15);
  lcd_dat(0x13);
  lcd_dat(0x13);
  lcd_dat(0x15);
  lcd_dat(0x19);
  lcd_dat(0x11);

  lcd_dat(0x0E);
  lcd_dat(0x11);
  lcd_dat(0x0E);
  lcd_dat(0x05);
  lcd_dat(0x0E);
  lcd_dat(0x14);
  lcd_dat(0x0A);
  lcd_dat(0x11);


  lcd_cmd(L_L2);

  for(i=0;i<16;i++)
  {
    lcd_dat(i%2);
    atraso_ms(100);
  }

//teste lcd
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste LCD"));
  
  for(i=32;i<128;i++)
  {
    if((i%16) == 0)lcd_cmd(L_L2);
    lcd_dat(i);
    atraso_ms(50);
  }

  atraso_ms(100);
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste LCD"));
  lcd_cmd(L_L2);
  lcd_str(rom2ram("       Ok"));
  atraso_ms(500);




//testa display 7s

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste 7 Seg"));


    PORTBbits.RB7=1;
    for(i=0;i<4;i++)
    {
      PORTB=0x10<<i;  
      for(tmp=0;tmp<16;tmp++)
      {
        PORTD=display7s(tmp);	 
        atraso_ms(200);	
      }
    }

  PORTD=0;

//testa LEDs

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+3);
  lcd_str(rom2ram("Teste LEDs"));

  for(tmp=0;tmp<3;tmp++)
    {
      for(i=1;i < 16;i=i*2)
      { 
        PORTB=i;
        atraso_ms(200);  
      }
    }
  PORTB=0;
  for(i=0;i<4;i++)
  {
    PORTB^=0x0F;
    atraso_ms(200);
  }  

//testa chaves


  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("  Teste Chaves"));

  tmp=0;

  while((tmp & 0x0F) != 0x0F)
  {
    TRISB=0x0F;

    if(PORTBbits.RB0 == 0)
    {
      tmp|=0x01;
    }
    if(PORTBbits.RB1 == 0)
    {
      tmp|=0x02;
    }
    if(PORTBbits.RB2 == 0)
    {
      tmp|=0x04;
    }
    if(PORTBbits.RB3 == 0)
    {
      tmp|=0x08;
    }
    
    TRISB=0x00;
    PORTB=tmp;
    atraso_ms(10);
  }
  PORTB=0; 


//teste EEPROM INT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("Teste EEPROM INT"));
// testar ? 
  lcd_cmd(L_L2);
  lcd_str(rom2ram(" (s=S1 n=S2) ?"));

  TRISB=0x03;

  while(PORTBbits.RB0 && PORTBbits.RB1);

  if(PORTBbits.RB0 == 0)
  {
    tmp=e2prom_r(10);
    lcd_dat(tmp);

    e2prom_w(10,0xA5);
    e2prom_w(10,0x5A);
    i=e2prom_r(10);

    e2prom_w(10,tmp);

    lcd_cmd(L_CLR);
    lcd_cmd(L_L1);
    lcd_str(rom2ram("Teste EEPROM INT"));
    lcd_cmd(L_L2);
    if(i == 0x5A) 
      lcd_str(rom2ram("       OK"));
    else
      lcd_str(rom2ram("      ERRO"));

    atraso_ms(1000);
  }
  else
  {
    while(PORTBbits.RB1 == 0);
  }

  TRISB=0x00;
  PORTB=0;

//teste EEPROM EXT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("Teste EEPROM EXT"));
// testar ? 
  lcd_cmd(L_L2);
  lcd_str(rom2ram(" (s=S1 n=S2) ?"));

  TRISB=0x03;

  while(PORTBbits.RB0 && PORTBbits.RB1);

  if(PORTBbits.RB0 == 0)
  {
    tmp=e2pext_r(10);
    lcd_dat(tmp);

    e2pext_w(10,0xA5);
    e2pext_w(10,0x5A);
    i=e2pext_r(10);

    e2pext_w(10,tmp);

    lcd_cmd(L_CLR);
    lcd_cmd(L_L1);
    lcd_str(rom2ram("Teste EEPROM EXT"));
    lcd_cmd(L_L2);
    if(i == 0x5A) 
      lcd_str(rom2ram("       OK"));
    else
      lcd_str(rom2ram("      ERRO"));

    atraso_ms(1000);
  }
  else
  {
    while(PORTBbits.RB1 == 0);
  }

  TRISB=0x00;
  PORTB=0;

//teste serial
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("Teste Serial TX"));
  lcd_cmd(L_L2+4);
  lcd_str(rom2ram("9600 8N1"));

  serial_tx_str(rom2ram("\r\n Picsimlab\r\n Teste Serial TX\r\n"));

  for(i=0;i<4;i++)
  {
    serial_tx(i+0x30);
    serial_tx_str(rom2ram(" PicsimLab\r\n"));
  }
  atraso_ms(1000);

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("Teste Serial RX"));
  serial_tx_str(rom2ram(" Digite!\r\n"));
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
       lcd_cmd(L_L2);
       serial_tx_str(rom2ram("\r\n"));
    }
    tmp=serial_rx(2000);
    lcd_dat(tmp);
    serial_tx(tmp);
  }
  atraso_ms(100);


//teste ADC
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram(" Teste ADC (P2)"));

  for(i=0; i< 200; i++)
  {
    tmp=((unsigned int)adc_amostra(1)*10)/204;
    lcd_cmd(L_L2+6);
    itoa(tmp,str); 
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('V');
    atraso_ms(10);
  }



//teste TEMP
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste TEMP"));

  for(i=0; i< 100; i++)
  {
    tmpi=((unsigned int) adc_amostra(0)*81)/100;
    lcd_cmd(L_L2+5);
    itoa(tmpi,str);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('C');
    atraso_ms(10);
  }


//teste Aquecimento
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste AQUEC"));
  PORTCbits.RC2=1;
  for(i=0; i< 100; i++)
  {
    tmpi=((unsigned int) adc_amostra(0)*81)/100;
    lcd_cmd(L_L2+5);
    itoa(tmpi,str);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('C');
    atraso_ms(10);
  }
  PORTCbits.RC2=0;


//teste Resfriamento
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste RESFR"));

//timer0 temporizador

 T0CONbits.T0CS=0;
 T0CONbits.PSA=0;
 T0CONbits.T08BIT=1;
 T0CONbits.T0PS0=0; // divide por 32
 T0CONbits.T0PS1=0;
 T0CONbits.T0PS2=1;
 T0CONbits.TMR0ON=1;

 INTCONbits.T0IE=1;

//T = 32x250x125 = 1segundo;

//timer1 contador
 T1CONbits.TMR1CS=1;
 T1CONbits.T1CKPS1=0;
 T1CONbits.T1CKPS0=0;


 INTCONbits.T0IF=0;
 TMR0H=0;
 TMR0L=6; //250
 cnt=125; 
 INTCONbits.GIE=1;

 TMR1H=0;
 TMR1L=0;
 T1CONbits.TMR1ON=1;

  PORTCbits.RC1=1;
  for(i=0; i< 150; i++)
  {
    tmpi=((unsigned int) adc_amostra(0)*81)/100;
    lcd_cmd(L_L2+2);
    itoa(tmpi,str);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('C');

    lcd_cmd(L_L2+8);
    itoa(t1cont,str);
    lcd_dat(str[1]);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(str[4]);
    lcd_dat('R');
    lcd_dat('P');
    lcd_dat('S');

    atraso_ms(10);
  }

  INTCONbits.GIE=0;
  PORTCbits.RC1=0;

//fim teste 
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("      Fim"));
  lcd_cmd(L_L2);
  lcd_str(rom2ram(" Pressione RST"));

  serial_tx_str(rom2ram("\r\n FIM!\r\n"));


   while(1);

}
Ejemplo n.º 15
0
//! Main loop.
int main(void){
  volatile unsigned int i;
  unsigned char app, verb;
  unsigned long len;
  // MSP reboot count for reset input & reboot function located at 0xFFFE
  volatile unsigned int reset_count = 0;
  
  silent=0; //Don't trust globals.
  
#if (platform == tilaunchpad)
  int ret=0;
  
  //ret = setjmp(warmstart);// needs to be here since context from init() would be gone
 warmstart:
  if (ret == 0) {	
    coldstart();	// basic hardware setup, clock to TUSB3410, and enable
  } else if (ret == 2) {
    dputs("\nalmost BSL only one RTS change\n");
  } else if (ret > 2) {	// reset released after more than two tst transisitions
    // We could write a BSL, a nice exercise for a Sunday afternoon.
    dputs("\nBSL\n");
    //call_BSL();	// once you are done uncomment ;-)
  } else {		// we come here after DTR high (release reset)
    dputs("\nWarmstart\n");
  }
#endif

#if (platform == donbfet)
  extern void donbfet_reboot(void);
  void (*reboot_function)(void) = donbfet_reboot;
#elif (platform == zigduino)
  extern void zigduino_reboot(void);
  void (*reboot_function)(void) = zigduino_reboot;
#else
  void (*reboot_function)(void) = (void *) 0xFFFE;
#endif
  
  init();
  
  txstring(MONITOR,OK,"http://goodfet.sf.net/");
  //txstring(0xab,0xcd,"http://goodfet.sf.net/");
  
  
  //Command loop.  There's no end!
  while(1){
    //Magic 3
    app = serial_rx();
    
    // If the app is the reset byte (0x80) increment and loop
    if (app == RESET){
      reset_count++;
	    
      if (reset_count > 4){
	// We could trigger the WDT with either:
	// WDTCTL = 0;
	// or
	// WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
	// but instead we'll jump to our reboot function pointer
	(*reboot_function)();
	debugstr("Rebooting not supported on this platform.");
      }
	    
      continue;
    }else {
      reset_count = 0;
    }
	  
    verb = serial_rx();
    len = rxword();
	  
    //Read data, looking for buffer overflow.
    if(len <= CMDDATALEN){
      for(i = 0; i < len; i++)
	  cmddata[i] = serial_rx();
	    
      handle(app,verb,len);
    }else {
      //Listen to the blaberring.
      for(i = 0; i < len; i++)
	serial_rx();
	    
      //Reply with an error.
      debugstr("Buffer length exceeded.");
      txdata(MONITOR,NOK,0);
    }
  }
}
Ejemplo n.º 16
0
/*
void isr() interrupt 0 {

}
*/
void main() {
  unsigned char i,tmp;

  CMCON=0x07; 
  TRISA=0x30;
  TRISB=0xE7;
  
  PORTA=0;
  PORTB=0;

  lcd_init();

  serial_init();

//teste serial
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Serial TX");
  lcd_cmd(L_L2+2);
  lcd_str("9600 8N1");

  serial_tx_str("\r\n Picsimlab\r\n Teste Serial TX\r\n");

  for(i=0;i<4;i++)
  {
    serial_tx(i+0x30);
    serial_tx_str(" PicsimLab\r\n");
  }
  atraso_ms(1000);

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Serial RX");
  serial_tx_str(" Digite!\r\n");
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
       lcd_cmd(L_L2);
       serial_tx_str("\r\n");
    }
    tmp=serial_rx(2000);
    lcd_dat(tmp);
    serial_tx(tmp);
  }
  atraso_ms(100);

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Teclado TX");
  serial_tx_str("\r\n Aguarde!\r\n");
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
      lcd_cmd(L_L2);
      serial_tx_str("\r\n");
    }
    tmp=tc_tecla(2000)+0x30;
    lcd_dat(tmp);
    serial_tx(tmp);
  }
  atraso_ms(100);


//fim teste 
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+4);
  lcd_str("Fim");
  lcd_cmd(L_L2+1);
  lcd_str("Pressione RST");

  serial_tx_str("\r\n FIM!\r\n");

  while(1);


}
Ejemplo n.º 17
0
void main() 
{
  unsigned char i;
  unsigned char tmp;
  unsigned int tmpi;

  char str[6];


  TRISA=0xC3;
  TRISB=0x01;
  TRISC=0x01;
  TRISD=0x00;
  TRISE=0x00;

#if defined(_16F877A) || defined(_16F777)  
#else  
  INTCON2bits.RBPU=0;
#endif

  lcd_init();
#ifndef _18F4550  
  i2c_init();
#endif  
  serial_init();
  adc_init();
  
#ifdef _18F452
  ADCON1=0x06;
#else
  ADCON1=0x0F;
  CMCON=0x07;
#endif

//dip
  TRISB=0x03;
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Ligue todos DIP");
  lcd_cmd(L_L2);
  lcd_str("Press. RB1");
  while(PORTBbits.RB1);


//testa caracter especial
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("   Teste LCD");
  
  for(i=0;i<10;i++)
  {
    atraso_ms(200);
    lcd_cmd(0x18);//display shift
  }
  
  for(i=0;i<10;i++)
  {
    atraso_ms(200);
    lcd_cmd(0x1C);//display shift
  }
  
  for(i=0;i<10;i++)
  {
    atraso_ms(200);
    lcd_cmd(0x10);
  }
  for(i=0;i<10;i++)
  {
    atraso_ms(200);
    lcd_cmd(0x14);
  }
  

  lcd_cmd(0x40);//endereço

  lcd_dat(0x11);
  lcd_dat(0x19);
  lcd_dat(0x15);
  lcd_dat(0x13);
  lcd_dat(0x13);
  lcd_dat(0x15);
  lcd_dat(0x19);
  lcd_dat(0x11);

  lcd_dat(0x0E);
  lcd_dat(0x11);
  lcd_dat(0x0E);
  lcd_dat(0x05);
  lcd_dat(0x0E);
  lcd_dat(0x14);
  lcd_dat(0x0A);
  lcd_dat(0x11);


  lcd_cmd(L_L2);

  for(i=0;i<16;i++)
  {
    lcd_dat(i%2);
    atraso_ms(100);
  }

//teste lcd
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("   Teste LCD");
  
  for(i=32;i>=32;i++)
  {
    if((i%16) == 0)lcd_cmd(L_L2); 
    lcd_dat(i);
    atraso_ms(50);
  }

  atraso_ms(100);
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("   Teste LCD");
  lcd_cmd(L_L2);
  lcd_str("       Ok");
  atraso_ms(500);


  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("   Beep");
  PORTCbits.RC1=1; //beep
  atraso_ms(500);
  PORTCbits.RC1=0;

//testa display 7s

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("   Teste 7 Seg");


#ifdef _18F452
  ADCON1=0x06;
#else
  ADCON1=0x0F;
#endif
    for(i=0;i<4;i++)
    {
      switch(i)
      {
         case 0: 
           PORTA=0x20;
           break;
         case 1: 
           PORTA=0x10;
           break;
         case 2: 
           PORTA=0x08;
           break;
         case 3: 
           PORTA=0x04;
           break;
       }

      for(tmp=0;tmp<16;tmp++)
      {
        PORTD=display7s(tmp);	 
        atraso_ms(200);	
      }
    }

#ifdef _18F452
  ADCON1=0x02;
#else
  ADCON1=0x0B;
#endif
  PORTD=0;


//dip
  TRISB=0x03;
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Desligue RTC DIP");
  lcd_cmd(L_L2);
  lcd_str("Press. RB1");
  while(PORTBbits.RB1);

//testa LEDs
  TRISB=0x00;
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+3);
  lcd_str("Teste LEDs");

  for(tmp=0;tmp<3;tmp++)
    {
      for(i=1;i > 0;i=i*2)
      { 
        PORTB=i;
        PORTD=i; 
        atraso_ms(200);  
      }
    }
  PORTB=0;
  PORTD=0;
  for(i=0;i<4;i++)
  {
    PORTB^=0xFF;
    PORTD^=0xFF;
    atraso_ms(200);
  }  

//testa chaves


  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("  Teste Chaves");

  tmp=0;
#ifdef _18F452
  ADCON1=0x06;
#else
  ADCON1=0x0F;
#endif
  TRISA|=0x20;

  TRISB=0x3F;
  lcd_cmd(L_L2);
  lcd_str(" RB0          ");
  while(PORTBbits.RB0);
  lcd_cmd(L_L2+6);
  lcd_str("Ok");
  atraso_ms(500);
  
  lcd_cmd(L_L2);
  lcd_str(" RB1          ");
  while(PORTBbits.RB1);
  lcd_cmd(L_L2+6);
  lcd_str("Ok");
  atraso_ms(500);
  
  lcd_cmd(L_L2);
  lcd_str(" RB2          ");
  while(PORTBbits.RB2);
  lcd_cmd(L_L2+6);
  lcd_str("Ok");
  atraso_ms(500);
  
  lcd_cmd(L_L2);
  lcd_str(" RB3          ");
  while(PORTBbits.RB3);
  lcd_cmd(L_L2+6);
  lcd_str("Ok");
  atraso_ms(500);
  
  lcd_cmd(L_L2);
  lcd_str(" RB4          ");
  while(PORTBbits.RB4);
  lcd_cmd(L_L2+6);
  lcd_str("Ok");
  atraso_ms(500);
  
  
  lcd_cmd(L_L2);
  lcd_str(" RB5          ");
  while(PORTBbits.RB5);
  lcd_cmd(L_L2+6);
  lcd_str("Ok");
  atraso_ms(500);
  
  lcd_cmd(L_L2);
  lcd_str(" RA5          ");
  while(PORTAbits.RA5);
  lcd_cmd(L_L2+6);
  lcd_str("Ok");
  atraso_ms(500);
  
  
/*
  while((tmp & 0x7F) != 0x7F)
  {
    TRISB=0x3F;

    if(PORTBbits.RB0 == 0)
    {
      tmp|=0x01;
    }
    if(PORTBbits.RB1 == 0)
    {
      tmp|=0x02;
    }
    if(PORTBbits.RB2 == 0)
    {
      tmp|=0x04;
    }
    if(PORTBbits.RB3 == 0)
    {
      tmp|=0x08;
    }
    if(PORTBbits.RB4 == 0)
    {
      tmp|=0x10;
    }
    if(PORTBbits.RB5 == 0)
    {
      tmp|=0x20;
    }
    if(PORTAbits.RA5 == 0)
    {
      tmp|=0x40;
    }

    
    TRISB=0x00;
    PORTB=tmp;
    atraso_ms(10);
  }

    atraso_ms(500);
*/
            
  PORTB=0; 
#ifdef _18F452
  ADCON1=0x02;
#else
  ADCON1=0x0B;
#endif


 
//teste serial
 lcd_cmd(L_CLR);
 lcd_cmd(L_L1);
 lcd_str("Teste Serial TX");
// testar ? 
  lcd_cmd(L_L2);
  lcd_str(" (s=RB0 n=RB1) ?");

  TRISB=0x03;
  while(PORTBbits.RB0 && PORTBbits.RB1);

  if(PORTBbits.RB0 == 0)
  {

  TRISCbits.TRISC7=1; //RX
  TRISCbits.TRISC6=0; //TX


  lcd_cmd(L_L2+4);
  lcd_str("9600 8N1");

  serial_tx_str("\r\n Picsimlab\r\n Teste Serial TX\r\n");

  for(i=0;i<4;i++)
  {
    serial_tx(i+0x30);
    serial_tx_str(" PicsimLab\r\n");
  }
  atraso_ms(1000);

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste Serial RX");
  serial_tx_str(" Digite!\r\n");
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
       lcd_cmd(L_L2);
       serial_tx_str("\r\n");
    }
    tmp=serial_rx(2000);
    lcd_dat(tmp);
    serial_tx(tmp);
  }
  atraso_ms(100);
  }

//teste ADC
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(" Teste ADC (P1)");

  for(i=0; i< 200; i++)
  {
    tmp=(adc_amostra(0)*10)/204;
    lcd_cmd(L_L2+6);
    itoa(tmp,str);
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('V');
    atraso_ms(10);
  }

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(" Teste ADC (P2)");

  for(i=0; i< 200; i++)
  {
    tmp=((unsigned int)adc_amostra(1)*10)/204;
    lcd_cmd(L_L2+6);
    itoa(tmp,str);
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('V');
    atraso_ms(10);
  }


//teste RELE

  TRISCbits.TRISC0=0;
  TRISEbits.TRISE0=0;

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste RELE 1");

  
  for(i=0;i<5;i++)
  {
    PORTCbits.RC0^=1;
    atraso_ms(500); 
  }
  PORTCbits.RC0=0; 

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste RELE 2");

  for(i=0;i<5;i++)
  {
    PORTEbits.RE0^=1;
    atraso_ms(500); 
  }
  PORTEbits.RE0=0;
//dip
  TRISB=0x03;
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Desl. REL1 DIP");
  lcd_cmd(L_L2);
  lcd_str("Press. RB1");
  while(PORTBbits.RB1);


//teste TEMP
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("   Teste TEMP");
  
  TRISA=0x07;

  adc_init();

  for(i=0; i< 100; i++)
  {
    tmpi=(adc_amostra(2)*10)/2;
    lcd_cmd(L_L2+5);
    itoa(tmpi,str);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('C');
    atraso_ms(20);
  }


//teste Aquecimento
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("   Teste AQUEC");
  PORTCbits.RC5=1;
  for(i=0; i< 100; i++)
  {
    tmpi=(adc_amostra(2)*10)/2;
    lcd_cmd(L_L2+5);
    itoa(tmpi,str);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('C');
    atraso_ms(50);
  }
  PORTCbits.RC5=0;


//teste Resfriamento

  TRISCbits.TRISC0=1;
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("   Teste RESFR");

//timer0 temporizador
#if defined(_16F877A) || defined(_16F777)  
 OPTION_REGbits.T0CS=0;
 OPTION_REGbits.PSA=0;
 OPTION_REGbits.PS0=0;
 OPTION_REGbits.PS1=0;
 OPTION_REGbits.PS2=1;
#else
 T0CONbits.T0CS=0;
 T0CONbits.PSA=0;
 T0CONbits.T08BIT=1;
 T0CONbits.T0PS0=0; // divide por 32
 T0CONbits.T0PS1=0;
 T0CONbits.T0PS2=1;
 T0CONbits.TMR0ON=1;
#endif
 
 
 INTCONbits.T0IE=1;

//T = 32x250x125 = 1segundo;

//timer1 contador
 T1CONbits.TMR1CS=1;
 T1CONbits.T1CKPS1=0;
 T1CONbits.T1CKPS0=0;


 INTCONbits.T0IF=0;
#if defined(_16F877A) || defined(_16F777)  
 TMR0=6;
#else
 TMR0H=0;
 TMR0L=6; //250
#endif
 cnt=125; 
 INTCONbits.GIE=1;

 TMR1H=0;
 TMR1L=0;
 T1CONbits.TMR1ON=1;

  PORTCbits.RC2=1;
  for(i=0; i< 150; i++)
  {
    tmpi=(adc_amostra(2)*10)/2;
    lcd_cmd(L_L2+2);
    itoa(tmpi,str);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('C');

    lcd_cmd(L_L2+8);
    itoa(t1cont,str);
    lcd_dat(str[1]);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(str[4]);
    lcd_dat('R');
    lcd_dat('P');
    lcd_dat('S');

    atraso_ms(10);
  }

  INTCONbits.GIE=0;
  PORTCbits.RC2=0;


#ifdef _18F452
  ADCON1=0x06;
#else
  ADCON1=0x0F;
#endif

#ifndef _18F4550
//teste RTC
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste RTC");
  
//ajuste  rtc_w();

//  rtc_w();
 
  rtc_r();
  lcd_cmd(L_L2);
  lcd_str((const char *)date);
   atraso_ms(2000);
  for(i=0;i<20;i++)
  {
    rtc_r();
    lcd_cmd(L_L2);;
    lcd_str((const char *)time);
    atraso_ms(500); 
  }
#endif

//dip
  TRISB=0x03;
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Des. DIS* e LED1");
  lcd_cmd(L_L2);
  lcd_str("Press. RB1");
  while(PORTBbits.RB1);



  TRISB=0xF8;
//teste Teclado
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+2);
  lcd_str("Teste Teclado");

  lcd_cmd(L_L2+1);

  i=0;
  while(i<14)
  {
    TRISD=0x0F;
    tmp=tc_tecla(1500)+0x30;
    TRISD=0x00;
    lcd_dat(tmp);
    i++;
  }


#ifndef _16F777
  TRISB=0x03;
//teste EEPROM INT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste EEPROM INT");
// testar ? 
  lcd_cmd(L_L2);
  lcd_str(" (s=RB0 n=RB1) ?");


  TRISB=0x03;

  while(PORTBbits.RB0 && PORTBbits.RB1);

  if(PORTBbits.RB0 == 0)
  {
    tmp=e2prom_r(10);
    lcd_dat(tmp);

    e2prom_w(10,0xA5);
    e2prom_w(10,0x5A);
    i=e2prom_r(10);

    e2prom_w(10,tmp);

    lcd_cmd(L_CLR);
    lcd_cmd(L_L1);
    lcd_str("Teste EEPROM INT");
    lcd_cmd(L_L2);
    if(i == 0x5A) 
      lcd_str("       OK");
    else
      lcd_str("      ERRO");

    atraso_ms(1000);
  }
  else
  {
    while(PORTBbits.RB1 == 0);
  }
#endif

#ifndef _18F4550
//teste EEPROM EXT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("Teste EEPROM EXT");
// testar ? 
  lcd_cmd(L_L2);
  lcd_str(" (s=RB0 n=RB1) ?");

  TRISB=0x03;

  while(PORTBbits.RB0 && PORTBbits.RB1);

  if(PORTBbits.RB0 == 0)
  {
    tmp=e2pext_r(10);
    lcd_dat(tmp);

    e2pext_w(10,0xA5);
    e2pext_w(10,0x5A);
    i=e2pext_r(10);

    e2pext_w(10,tmp);

    lcd_cmd(L_CLR);
    lcd_cmd(L_L1);
    lcd_str("Teste EEPROM EXT");
    lcd_cmd(L_L2);
    if(i == 0x5A) 
      lcd_str("       OK");
    else
      lcd_str("      ERRO");

    atraso_ms(1000);
  }
  else
  {
    while(PORTBbits.RB1 == 0);
  }
#endif
  TRISB=0x00;
  PORTB=0;


//fim teste 
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str("      Fim");
  lcd_cmd(L_L2);
  lcd_str(" Pressione RST");

  serial_tx_str("\r\n FIM!\r\n");


   while(1);

}