Primeros pasos con PIC (MikroC)

Muchas gracias josemaX un pequeño detalle, creeme que despues de horas de estar viendo, pensando y generando un programa hay momentos en que ya no se percata uno de esos detalles.

Gracias nuevamente.
 
Hola a todos,
Solo quiero compartir con ustedes chicos, llamé a este proyecto es el foro, puede traer este proyecto a su oficina en su escritorio.
Significa voluntad dada la información cuando usted sale de su escritorio, tal vez quieres ir satisfacer al cliente o simplemente quiere comer.
En el apego hay código MikroC y Proteus, puede cambios que palabra así lo desea, asegúrese de que necesita contar los caracteres.
Adjunta archivos.

Gracias,
Kapoh.
 

Adjuntos

  • MessageBoard.rar
    32.1 KB · Visitas: 13
Hola a todos,
Este es proyecto de la muestra con el botón, este proyecto es encendido y apagado, también hay función momentánea y biestables.
La didiference en este proyecto llama a ON directamente a la conducción de puerta BS170, luego BS170 estará conectado a tierra, una vez conectado la fuente distribuirá a VDD PIC16F628A, bien que deba sostener la puerta BS170, por lo que tengo que hacer alto el puerto al holding BS170 ha Ve a riger.

Gracias,
Kapoh.
 

Adjuntos

  • Button For Foros.rar
    33.3 KB · Visitas: 10
buenas, necesito ayuda para encender un led con un switch programado con mikroc en un pic 18f4550 esto es lo que llevo pero no se por que no funciona, gracias por la colaboración que me pueda ser brindada.
 

Adjuntos

  • led.txt
    147 bytes · Visitas: 13
  • prot.JPG
    prot.JPG
    74.5 KB · Visitas: 6
buenas, necesito ayuda para encender un led con un switch programado con mikroc en un pic 18f4550 esto es lo que llevo pero no se por que no funciona, gracias por la colaboración que me pueda ser brindada.
Hola,
Ojo que cuando escribís "PORTA.F0=P;" estás asignando a un bit(un bit dentro del PORTA) un entero (de 2 bytes).
Como cuando ponés "TRISA=1;" estás declarando que solamente A0 será entrada y no todo el puerto, para que las 8 patitas del pto sean entradas deberías asignar el valor 255 o 0XFF etc. Ídem con TRISD.
Tampoco estás inicializando las variables L y P.
 
Buena tarde tengo un problema

Estoy usando un sensor de temperatura Ds1822 que ya tengo su programación y funciona, pero ahora quiero activar una salida del puerto b y no me activa
quiero que a cierta temperatura se active o lo contario se apague

Uso Pic16f876a y estoy programando con microC

les dejo el codigo para ver que estoy haciendo mal

Saludos

Código:
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RC3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// end LCD module connections dim as byte tem
int raw_temp;
char *temp = "000.00 C";

void main() {
  ADCON1 = 0x07;                         //Configura puerto A como digitales
  PORTB = 0xFF;
  INTCON = 0;
  TRISB = 0xff;
  Lcd_Init();                      // Initialize LCD module
  Lcd_Cmd(_LCD_CURSOR_OFF);        // cursor off
  Lcd_Cmd(_LCD_CLEAR);             // clear LCD
  lcd_out(1, 3, "Temperatura:");

  while(1) {

    Ow_Reset(&PORTA, 1);                         // Onewire reset signal
    Ow_Write(&PORTA, 1, 0xCC);                   // Issue command SKIP_ROM
    Ow_Write(&PORTA, 1, 0x44);                   // Issue command CONVERT_T

    while(Ow_Read(&PORTA, 1) == 0) ;
    Ow_Reset(&PORTA, 1);                         // Onewire reset signal
    Ow_Write(&PORTA, 1, 0xCC);                   // Issue command SKIP_ROM
    Ow_Write(&PORTA, 1, 0xBE);                   // Issue command READ_SCRATCHPAD

    raw_temp  = Ow_Read(&PORTA, 1);              // Read temperature LSB byte
    raw_temp |= (Ow_Read(&PORTA, 1) << 8);       // Read temperature MSB byte

    if(raw_temp & 0x8000) {                       // If the temperature is negative
      temp[0] = '-';                              // Put minus sign (-)
      raw_temp = ~raw_temp + 1;                   // Change temperature value to positive form
    }
    else {
      if((raw_temp >> 4) >= 100)                  // If the temperatue >= 100 °C
        temp[0] = '1';                            // Put 1 of hundreds
      else                                        // otherwise
        temp[0] = ' ';                            // put space ' '
    }

    // Put the first two digits ( for tens and ones)
    temp[1] = ( (raw_temp >> 4) / 10 ) % 10 + 48;      // Put tens digit
    temp[2] =   (raw_temp >> 4)        % 10  + 48;     // Put ones digit

    // Put the 4 fraction digits (digits after the point)
    // Why 625: because we're working with 12-bit resolution
    temp[4] = ( (raw_temp & 0x0F) * 625) / 1000 + 48;          // Put thousands digit
    temp[5] = (((raw_temp & 0x0F) * 625) / 100 ) % 10 + 48;    // Put hundreds digit
    temp[6] = 223;                                // Put degree symbol ( ° )
    lcd_out(2, 4, temp);                          // Display temperature

    delay_ms(1000);                               // Wait 1 second
  }
if(raw_temp>40)                                   // cuando llegue a mas de 40
    {
    PORTB.rb0 = 0;                                // se activa portb .0
    }
    if(raw_temp<40)                               // cuando es menor de 40
    {
    PORTB.rb0 = 1;                                  // se apaga portb .0
    }
}
// End of code
 
Perfecto, muchas gracias, era eso, no lo había notado, estoy empezando con Microc

Pregunta, ahora lo que tengo que hacer que presionando un botón me lleve a un menú

Ejemplo :

If port.rb1 = 1

Else

If portb.rb1= 0 se regresa a_la pantalla principal


La lcd mostrará
Configurar temperatura " 35°C " tem

If portb.rb2 = 1 el botón incrementa en 1
Tem + 1

If portb.rb3 = 1 el botón baja en 1
Tem - 1


¿Como seria para crear las variables y poder hacer ese menú?

Muchas gracias y saludos.
 
Buenos días tengo el siguiente problema y ya e buscado y no encuentro como hacerlo les comento.
Es un control de de Temperara
tengo una variable de inicio llamada tem1=35;
con esta variable inicia el programa y que si es menor a 35 se activa si es mayor a 35 de desactiva
hasta ahí esta bien.
ahora tengo que incluir un botón o selector que al momento sea =1 en la lcd me muestre ajustes y me muestre la variable tem1=35
para si con unos pulsadores poder modificar esa variable ya sea que incremente o disminuye

hasta el momento no e podido como hacer que me muestre la variable en la lcd
y cuando el pulsador esta en 1 me muestra ajustes pero no me muestra la variable

les dejo el código que tengo hasta el momento



Código:
// Lcd pinout settings
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RC3_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D4 at RC4_bit;
sbit led at RB0_bit;
sbit mas at RB1_bit;
sbit menos at RB2_bit;
sbit men at RB3_bit;
// Pin direction
sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D7_Direction at TRISC7_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit led_dir at TRISB0_bit;

char tem1;
int raw_temp;
char *temp = "000.00 C";

void main() {
  ADCON1 = 0x07;                         //Configura puerto A como digitales
  led_dir = 0;
  Lcd_Init();                      // Initialize LCD module
  Lcd_Cmd(_LCD_CURSOR_OFF);        // cursor off
  Lcd_Cmd(_LCD_CLEAR);             // clear LCD
  lcd_out(1, 3, "TEMPERATURA");
  led = 0;
  tem1  = 35;
  men = 0;
  mas = 0;
  menos = 0;

  while(1) {
    Ow_Reset(&PORTA, 1);                         // Onewire reset signal
    Ow_Write(&PORTA, 1, 0xCC);                   // Issue command SKIP_ROM
    Ow_Write(&PORTA, 1, 0x44);                   // Issue command CONVERT_T
    while(Ow_Read(&PORTA, 1) == 0) ;
    Ow_Reset(&PORTA, 1);                         // Onewire reset signal
    Ow_Write(&PORTA, 1, 0xCC);                   // Issue command SKIP_ROM
    Ow_Write(&PORTA, 1, 0xBE);                   // Issue command READ_SCRATCHPAD
    raw_temp  = Ow_Read(&PORTA, 1);              // Read temperature LSB byte
    raw_temp |= (Ow_Read(&PORTA, 1) << 8);       // Read temperature MSB byte
    if(raw_temp & 0x8000) {                       // If the temperature is negative
      temp[0] = '-';                              // Put minus sign (-)
      raw_temp = ~raw_temp + 1;                   // Change temperature value to positive form
    }else {
     if((raw_temp >> 4) <= tem1){
      Lcd_Cmd(_LCD_CLEAR);             // clear LCD
     lcd_out(1, 3, tem1);
       led = 1;
       }else {
      Lcd_Cmd(_LCD_CURSOR_OFF);        // cursor off
       Lcd_Cmd(_LCD_CLEAR);             // clear LCD
       lcd_out(1, 3, "Tem Estable:");
       led = 0;
      }
      if((raw_temp >> 4) >= 100)                  // If the temperatue >= 100 °C
        temp[0] = '1';                            // Put 1 of hundreds
      else                                        // otherwise
        temp[0] = ' ';                            // put space ' '

    }
    // Put the first two digits ( for tens and ones)
    temp[1] = ( (raw_temp >> 4) / 10 ) % 10 + 48;      // Put tens digit
    temp[2] =   (raw_temp >> 4)        % 10  + 48;     // Put ones digit
    // Put the 4 fraction digits (digits after the point)
    // Why 625: because we're working with 12-bit resolution
    temp[4] = ( (raw_temp & 0x0F) * 625) / 1000 + 48;          // Put thousands digit
    temp[5] = (((raw_temp & 0x0F) * 625) / 100 ) % 10 + 48;    // Put hundreds digit
    temp[6] = 223;  // Put degree symbol ( ° )
    lcd_out(2, 4, temp);   // Display temperature

    delay_ms(500);


   }
    }
 
Que tal buena tarde a todos.

tengo un proyecto con una pantalla stone de 7 pulgas para visualizar temperatura y humedad y set point.
la programación con MicroC ya la tengo hecha y puedo visualizar los valores via serial

El problema que tengo es lo siguiente, no e podido hacer la comunicación o como es la programación para mandarla a la pantalla le dejo mi código que estoy ocupando e leído pero no le entiendo
Le dejo la hoja de datos de la pantalla

si me podrían ayudar se los agradeceré mucho saludos

Código:
  // Lcd pinout setting FUNCIONA SIN ERRORES EN PROTEUS funcionando al 100 en proto con sensor


#include "floattostr_.h"



 sbit CALEFACTOR at RB0_bit;
 int tem1;
 char Text[10]; //Cadena de caracteres para impresión de datos.
 char fracc;
 char hume;
 char texto[30];
 unsigned int HUM1;
 unsigned char  Check, T_byte1, T_byte2, RH_byte1, RH_byte2, Ch ;
 unsigned Temp, RH, Sum ;
 unsigned be, me,ne, Sum2,h1,h2 ;

 //////////////////////////////
 
 void Uart1_write_text_const(const char *info)
{
 while(*info) UART1_Write(*info++);
}

 //////////////////////////////
 void StartSignal(){
 TRISA.F0 = 0;    //Configure RD0 as output
 PORTA.F0 = 0;    //RD0 sends 0 to the sensor
 delay_ms(18);
 PORTA.F0 = 1;    //RD0 sends 1 to the sensor
 delay_us(30);
 TRISA.F0 = 1;    //Configure RD0 as input
  }
 //////////////////////////////
 void CheckResponse(){
 Check = 0;
 delay_us(40);
 if (PORTA.F0 == 0){
 delay_us(80);
 if (PORTA.F0 == 1)   Check = 1;   delay_us(40);}
 }
 //////////////////////////////
 char ReadData(){
 char i, j;
 for(j = 0; j < 8; j++){
 while(!PORTA.F0); //Wait until PORTD.F0 goes HIGH
 delay_us(30);
 if(PORTA.F0 == 0)
       i&= ~(1<<(7 - j));  //Clear bit (7-b)
 else {i|= (1 << (7 - j));  //Set bit (7-b)
 while(PORTA.F0);}  //Wait until PORTD.F0 goes LOW
 }
 return i;
 }
 //////////////////////////////

 void main() {
  UART1_Init(9600);
 Uart1_write_text_const("INICIANDO\r\n");
  TEM1=350;
 ADCON1 = 0x07;   //Configura puerto A como digitales
 while(1){
  StartSignal();
  CheckResponse();
  if(Check == 1){
  RH_byte1 = ReadData();
  RH_byte2 = ReadData();
  T_byte1 = ReadData();
  T_byte2 = ReadData();
  Sum = ReadData();
  if(Sum == ((RH_byte1+RH_byte2+T_byte1+T_byte2) & 0XFF)){
  Temp = T_byte1;
  Temp = (Temp << 8) | T_byte2;
  RH = RH_byte1;
  RH = (RH << 8) | RH_byte2;
  delay_ms(500);

  

    sprinti(texto,"HUMEDAD=%u \r\n",rh);
    UART1_Write_Text(texto);
    
    sprinti(texto,"Temperatura=%u \r\n",TEMP);
    UART1_Write_Text(texto);
     delay_ms(500);
 } else {
    CALEFACTOR=0;






   }
}
}
 

Adjuntos

  • User Development Guide.pdf
    1.9 MB · Visitas: 5
Buen día.
Soy principiante en programación con MikroC, tengo que controlar la velocidad de un motor de 12V cambiando el ciclo de trabajo ingresando el ciclo de 0 a 255 por teclado matricial, como el que está en el diagrama de Proteus.
Estoy utilizando un PIC16F887.

El porcentaje correspondiente ingresado debe aparecer en el LCD y por consiguiente variar la velocidad del motor.

Lo que me falta lograr es hacer que dicha cantidad ingresada, se transforme a porcentaje y asignarla a la variable de ciclo de trabajo de PWM. Estoy utilizando las librerías de Keypad, PWM y LCD que vienen en MikroC.

Por ejemplo: (dutycycle/100)*255, pero no sé cómo implementar la fórmula dentro del código.

¿Me pueden ayudar a checarlo y decirme cómo corregirlo? Gracias de antemano.

Aquí esta mi código:
C:
#define pwm PORTC.F2

char txt[6]=" ";
unsigned char kp;
int i=0;
int ciclo=0;

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

// End LCD module connections
char keypadPort at PORTD;

char teclado(){
kp = 0;

do{
kp = Keypad_Key_Click();
}

while (kp==0);

switch(kp){
      case  1: kp = 49; break; // 1       
      case  2: kp = 50; break; // 2
      case  3: kp = 51; break; // 3
      case  4: kp = 65; break; // A
      case  5: kp = 52; break; // 4
      case  6: kp = 53; break; // 5
      case  7: kp = 54; break; // 6
      case  8: kp = 66; break; // B
      case  9: kp = 55; break; // 7
      case 10: kp = 56; break; // 8
      case 11: kp = 57; break; // 9
      case 12: kp = 67; break; // C
      case 13: kp = 42; break; // *
      case 14: kp = 48; break; // 0
      case 15: kp = 35; break; // #
      case 16: kp = 68; break; // D
    }
    return kp;
}

void main(){
ANSEL=0;
ANSELH=0;
c1on_bit=0;
c1on_bit=0;

TRISA=0X00;
PORTA=0X00;
TRISB=0X00;
PORTB=0X00;
TRISC=0X00;
PORTC=0X00;
TRISD=0X00;
PORTD=0X00;
TRISE=0X00;
PORTE=0X00;

 Lcd_init();
 Lcd_cmd(_LCD_CLEAR);
 Lcd_cmd(_LCD_CURSOR_OFF);

 Keypad_Init();
    
 Lcd_out(1,1,"Valor: ");

 while(1){
txt=teclado();
Lcd_chr_cp(txt);
 i++;

PWM1_Set_Duty(ciclo);

if(i==3){
 delay_ms(500);
  Lcd_cmd(1);
  Lcd_Out(1, 1, "Ciclo de trabajo:");
  Lcd_Out(2, 1, txt);
  Lcd_Out(2, 4, "%");
 }
 }
 }
Y adjunto el diagrama en Proteus 8.9
 

Adjuntos

  • diagrama.jpg
    diagrama.jpg
    429.4 KB · Visitas: 4
  • Practica12.rar
    22.6 KB · Visitas: 3
Buen día.
Soy principiante en programación con MikroC, tengo que controlar la velocidad de un motor de 12V cambiando el ciclo de trabajo ingresando el ciclo de 0 a 255 por teclado matricial, como el que está en el diagrama de Proteus.
Estoy utilizando un PIC16F887.

El porcentaje correspondiente ingresado debe aparecer en el LCD y por consiguiente variar la velocidad del motor.

Lo que me falta lograr es hacer que dicha cantidad ingresada, se transforme a porcentaje y asignarla a la variable de ciclo de trabajo de PWM. Estoy utilizando las librerías de Keypad, PWM y LCD que vienen en MikroC.

Por ejemplo: (dutycycle/100)*255, pero no sé cómo implementar la fórmula dentro del código.

¿Me pueden ayudar a checarlo y decirme cómo corregirlo? Gracias de antemano.

Aquí esta mi código:
C:
#define pwm PORTC.F2

char txt[6]=" ";
unsigned char kp;
int i=0;
int ciclo=0;

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

// End LCD module connections
char keypadPort at PORTD;

char teclado(){
kp = 0;

do{
kp = Keypad_Key_Click();
}

while (kp==0);

switch(kp){
      case  1: kp = 49; break; // 1      
      case  2: kp = 50; break; // 2
      case  3: kp = 51; break; // 3
      case  4: kp = 65; break; // A
      case  5: kp = 52; break; // 4
      case  6: kp = 53; break; // 5
      case  7: kp = 54; break; // 6
      case  8: kp = 66; break; // B
      case  9: kp = 55; break; // 7
      case 10: kp = 56; break; // 8
      case 11: kp = 57; break; // 9
      case 12: kp = 67; break; // C
      case 13: kp = 42; break; // *
      case 14: kp = 48; break; // 0
      case 15: kp = 35; break; // #
      case 16: kp = 68; break; // D
    }
    return kp;
}

void main(){
ANSEL=0;
ANSELH=0;
c1on_bit=0;
c1on_bit=0;

TRISA=0X00;
PORTA=0X00;
TRISB=0X00;
PORTB=0X00;
TRISC=0X00;
PORTC=0X00;
TRISD=0X00;
PORTD=0X00;
TRISE=0X00;
PORTE=0X00;

 Lcd_init();
 Lcd_cmd(_LCD_CLEAR);
 Lcd_cmd(_LCD_CURSOR_OFF);

 Keypad_Init();
   
 Lcd_out(1,1,"Valor: ");

 while(1){
txt=teclado();
Lcd_chr_cp(txt);
 i++;

PWM1_Set_Duty(ciclo);

if(i==3){
 delay_ms(500);
  Lcd_cmd(1);
  Lcd_Out(1, 1, "Ciclo de trabajo:");
  Lcd_Out(2, 1, txt);
  Lcd_Out(2, 4, "%");
 }
 }
 }
Y adjunto el diagrama en Proteus 8.9
Adjunto programa modificado para que pruebes
 

Adjuntos

  • Practica12.rar
    59.1 KB · Visitas: 5
Atrás
Arriba