Autor Tema: Mini curso "Programación en XC8"  (Leído 455462 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Mini curso "Programación en XC8"
« Respuesta #270 en: 18 de Octubre de 2014, 17:51:57 »
Hola alguien puede explicarme esta parte de código de la librería xlcd.h:
Código: [Seleccionar]
/* DATA_PORT defines the port to which the LCD data lines are connected */
 #define DATA_PORT       PORTC
 #define TRIS_DATA_PORT TRISC

/* CTRL_PORT defines the port where the control lines are connected.
 * These are just samples, change to match your application.
 */
 #define RW_PIN   LATBbits.LATC6   /* PORT for RW */
 #define TRIS_RW  TRISBbits.TRISC6     /* TRIS for RW */

 #define RS_PIN   LATBbits.LATC5   /* PORT for RS */
 #define TRIS_RS  TRISBbits.TRISC5     /* TRIS for RS */

 #define E_PIN    LATBbits.LATC4   /* PORT for E  */
 #define TRIS_E   TRISBbits.TRISC4     /* TRIS for E  */

Entiendo que si quiero usar el Puerto B escribo:
Código: [Seleccionar]
#define DATA_PORT         PORTB
#define TRIS_DATA_PORT TRISB
Lo que no entiendo es la parte de control que pone por ejemplo: RS_PIN  LATBbits.LATC5 que es LATB o LATC.

Gracias.

« Última modificación: 18 de Octubre de 2014, 18:00:27 por Miquel_S »
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado sander

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 624
Re: Mini curso "Programación en XC8"
« Respuesta #271 en: 18 de Octubre de 2014, 18:45:26 »
Los PIC18F traen tres registros para manejar cada puerto, TRISx(para configurar), PORTx(para leer del puerto) y LATx(para escribir en el puerto), aumentaron el registro LAT para solucionar algunos problemas que podrian ocurrir en los PIC16F al acceder a los puertos con las instrucciones bcf , bsf y otras mas, ya que estas instrucciones realmente no trabajan sobre los bits individuales del puesto, si no que leen todo el puerto, modifican el bit requerido y vuelven escribir en el puerto, esto a veces hacia que se cambien otros valores del puerto accidentalmente.

Este problema esta bastante documentado rmw effect.

Resumiendo en los PIC16F1 y PIC18F usar PORT para leer y LAT para escribir.

Saludos.
La electrónica es el arte de manipular señales eléctricas que transportan información
Jan Davidse

Visita mi blog
Visita mi canal de youtube

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Mini curso "Programación en XC8"
« Respuesta #272 en: 18 de Octubre de 2014, 18:50:53 »
Lo siento pero sigo sin saber donde modificar para usar un determinado bit de un determinado puerto.

Gracias
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado sander

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 624
Re: Mini curso "Programación en XC8"
« Respuesta #273 en: 18 de Octubre de 2014, 19:02:18 »
Lo siento pero sigo sin saber donde modificar para usar un determinado bit de un determinado puerto.

Gracias

Pero preguntaste que es LATB y LATC  :?

Bueno,
Código: C
  1. //si quieres usar el pin RB5 como salida  usas
  2. #define RS PIN  LATBbits.LATB5
  3. // si quieres usar el pin RC0 para escribir usas
  4. #define RS PIN LATCbits.LATC0
La electrónica es el arte de manipular señales eléctricas que transportan información
Jan Davidse

Visita mi blog
Visita mi canal de youtube

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Mini curso "Programación en XC8"
« Respuesta #274 en: 18 de Octubre de 2014, 19:12:42 »
Perdón no hice la pregunta bien, lo que queria preguntar era que como esta escrito:
Código: [Seleccionar]
#define RS_PIN   LATBbits.LATC5    /* PORT for RS */
 #define TRIS_RS  TRISBbits.TRISC5    /* TRIS for RS */
esta mezclando LATBbits con LATC5 y TRISBbits con LATC5 y eso es lo que no entendia pero sera que hay un error.

Gracias.
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado sander

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 624
Re: Mini curso "Programación en XC8"
« Respuesta #275 en: 18 de Octubre de 2014, 19:22:30 »
Si eso esta equivocado, deberia salirle error al compilar.

Saludos
La electrónica es el arte de manipular señales eléctricas que transportan información
Jan Davidse

Visita mi blog
Visita mi canal de youtube

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Mini curso "Programación en XC8"
« Respuesta #276 en: 18 de Octubre de 2014, 19:40:43 »
Gracias por la ayuda sander, al compilar no salia ningún error.

Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Mini curso "Programación en XC8"
« Respuesta #277 en: 18 de Octubre de 2014, 20:57:27 »
Alguien seria tan amable de revisar este código y decirme si tengo algún error, lo digo porque me salen caracteres extraños y así poder descartar que sea el código.
main.c
Código: [Seleccionar]
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include "my_xlcd.h"
#include <plib/delays.h>


#pragma config PLLDIV = 5       // PLL Prescaler Selection bits (Divide by 5 (20 MHz oscillator input))
#pragma config CPUDIV = OSC1_PLL2// System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
#pragma config USBDIV = 2       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes from the 96 MHz PLL divided by 2)
#pragma config FOSC = HSPLL_HS  // Oscillator Selection bits (HS oscillator, PLL enabled (HSPLL))
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
#pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOR = ON         // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 3         // Brown-out Reset Voltage bits (Minimum setting)
#pragma config VREGEN = OFF     // USB Voltage Regulator Enable bit (USB voltage regulator disabled)
#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)
#pragma config CCP2MX = ON      // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF     // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
#pragma config LPT1OSC = OFF    // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON       // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF        // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM is not code-protected)
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)


#define _XTAL_FREQ 48000000

//Retardos requeridos por la librería XLCD
void DelayFor18TCY(void);
void DelayPORXLCD(void);
void DelayXLCD(void);

void main(void)
{
 ADCON1 = 0b1111;
 //Configurando LCD 4 bits mutilínea
 OpenXLCD(FOUR_BIT & LINES_5X7);
 //Esperar hasta que el display esté disponible.
 while(BusyXLCD());
 //Mover cursor a la derecha...
 WriteCmdXLCD(0x06);
 //Desactivando el cursor.
 WriteCmdXLCD(0x0C);

 while(1)
 {
 //Primera línea
 SetDDRamAddr(0x00);
 putrsXLCD("HOLA");
 //Segunda línea
 SetDDRamAddr(0x40);
 putrsXLCD("MUNDO");
 }

}
void DelayFor18TCY(void)
{
 Delay10TCYx(120);
 return;
}

void DelayPORXLCD(void)
{
 Delay1KTCYx(180);
 return;
}

void DelayXLCD(void)
{
 Delay1KTCYx(60);
 return;
}
my_xlcd.h
Código: [Seleccionar]
#ifndef __XLCD_H
#define __XLCD_H
#include "p18cxxx.h"
/* PIC18 XLCD peripheral routines.
 *
 *   Notes:
 *      - These libraries routines are written to support the
 *        Hitachi HD44780 LCD controller.
 *      - The user must define the following items:
 *          - The LCD interface type (4- or 8-bits)
 *          - If 4-bit mode
 *              - whether using the upper or lower nibble
 *          - The data port
 *              - The tris register for data port
 *              - The control signal ports and pins
 *              - The control signal port tris and pins
 *          - The user must provide three delay routines:
 *              - DelayFor18TCY() provides a 18 Tcy delay
 *              - DelayPORXLCD() provides at least 15ms delay
 *              - DelayXLCD() provides at least 5ms delay
 */

/* Interface type 8-bit or 4-bit
 * For 8-bit operation uncomment the #define BIT8
 */
/* #define BIT8 */

/* When in 4-bit interface define if the data is in the upper
 * or lower nibble.  For lower nibble, comment the #define UPPER
 */
/* #define UPPER */

/* DATA_PORT defines the port to which the LCD data lines are connected */
 #define DATA_PORT      PORTB
 #define TRIS_DATA_PORT TRISB

/* CTRL_PORT defines the port where the control lines are connected.
 * These are just samples, change to match your application.
 */
 #define RW_PIN   LATBbits.LATB2    /* PORT for RW */
 #define TRIS_RW  TRISBbits.TRISB2    /* TRIS for RW */

 #define RS_PIN   LATBbits.LATB0    /* PORT for RS */
 #define TRIS_RS  TRISBbits.TRISB0    /* TRIS for RS */

 #define E_PIN    LATBbits.LATB1  /* PORT for E  */
 #define TRIS_E   TRISBbits.TRISB1    /* TRIS for E  */

/* Display ON/OFF Control defines */
#define DON         0b00001111  /* Display on      */
#define DOFF        0b00001011  /* Display off     */
#define CURSOR_ON   0b00001111  /* Cursor on       */
#define CURSOR_OFF  0b00001101  /* Cursor off      */
#define BLINK_ON    0b00001111  /* Cursor Blink    */
#define BLINK_OFF   0b00001110  /* Cursor No Blink */

/* Cursor or Display Shift defines */
#define SHIFT_CUR_LEFT    0b00000100  /* Cursor shifts to the left   */
#define SHIFT_CUR_RIGHT   0b00000101  /* Cursor shifts to the right  */
#define SHIFT_DISP_LEFT   0b00000110  /* Display shifts to the left  */
#define SHIFT_DISP_RIGHT  0b00000111  /* Display shifts to the right */

/* Function Set defines */
#define FOUR_BIT   0b00101100  /* 4-bit Interface               */
#define EIGHT_BIT  0b00111100  /* 8-bit Interface               */
#define LINE_5X7   0b00110000  /* 5x7 characters, single line   */
#define LINE_5X10  0b00110100  /* 5x10 characters               */
#define LINES_5X7  0b00111000  /* 5x7 characters, multiple line */

#ifdef _OMNI_CODE_
#define PARAM_SCLASS
#else
#define PARAM_SCLASS auto
#endif

#ifndef MEM_MODEL
#ifdef _OMNI_CODE_
#define MEM_MODEL
#else
#define MEM_MODEL far  /* Change this to near for small memory model */
#endif
#endif

/* OpenXLCD
 * Configures I/O pins for external LCD
 */
void OpenXLCD(PARAM_SCLASS unsigned char);

/* SetCGRamAddr
 * Sets the character generator address
 */
void SetCGRamAddr(PARAM_SCLASS unsigned char);

/* SetDDRamAddr
 * Sets the display data address
 */
void SetDDRamAddr(PARAM_SCLASS unsigned char);

/* BusyXLCD
 * Returns the busy status of the LCD
 */
unsigned char BusyXLCD(void);

/* ReadAddrXLCD
 * Reads the current address
 */
unsigned char ReadAddrXLCD(void);

/* ReadDataXLCD
 * Reads a byte of data
 */
char ReadDataXLCD(void);

/* WriteCmdXLCD
 * Writes a command to the LCD
 */
void WriteCmdXLCD(PARAM_SCLASS unsigned char);

/* WriteDataXLCD
 * Writes a data byte to the LCD
 */
void WriteDataXLCD(PARAM_SCLASS char);

/* putcXLCD
 * A putc is a write
 */
#define putcXLCD WriteDataXLCD

/* putsXLCD
 * Writes a string of characters to the LCD
 */
void putsXLCD(PARAM_SCLASS char *);

/* putrsXLCD
 * Writes a string of characters in ROM to the LCD
 */
void putrsXLCD(const char *);

/* User defines these routines according to the oscillator frequency */
extern void DelayFor18TCY(void);
extern void DelayPORXLCD(void);
extern void DelayXLCD(void);

#endif


Gracias.
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado illusionista_86

  • PIC10
  • *
  • Mensajes: 23
Re: Mini curso "Programación en XC8"
« Respuesta #278 en: 20 de Octubre de 2014, 11:04:25 »
Miquel_s, en la libreria tuya de XLCD, creo que estas poniendo E, RW y RS en la parte baja del puerto B, pues si te fijas mas arriba de tu codigo hay una parte donde pone:

/* When in 4-bit interface define if the data is in the upper
 * or lower nibble.  For lower nibble, comment the #define UPPER
 */
/* #define UPPER */

la tienes comentada, con lo cual se esta utilizando tambien la parte baja para los datos, descomentala para ver que pasa.

esto te lo digo de forma rapida, no tengo mucho tiempo de ver mas cosas ahora, si no funciona, lo dices...

y yo de normal para ir a una posicion dada de la pantalla utilizao "lcd_gotoXY()", tambien suelo definir los delays en el mismo archivo que esta el "main" de mi proyecto, al igual que la funcion "command"

Desconectado rotting79

  • PIC12
  • **
  • Mensajes: 91
Re: Mini curso "Programación en XC8"
« Respuesta #279 en: 21 de Octubre de 2014, 01:45:36 »
...On November 2nd, a PIC10 became self-aware and decided our fate in __delay_us ( 1 ); ...

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Mini curso "Programación en XC8"
« Respuesta #280 en: 21 de Octubre de 2014, 05:28:28 »
Thanks rotting79, I will review your program.

Greetings.
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado illusionista_86

  • PIC10
  • *
  • Mensajes: 23
Re: Mini curso "Programación en XC8"
« Respuesta #281 en: 23 de Octubre de 2014, 12:08:00 »
el siguiente codigo no deveria de ir aqui porque es para CCS, pero es un ejemplo que he realizado utilizando la filosofia que he comentado para el control de servos, en este caso son 8 servos, y ademas he realizado una aplicacion en visual basic 2013 para controlar los 8 servos desde el pc, conectando la placa entrenadora al pc por el puerto com.


Código: C
  1. ////////////////////////////////////////////////////////////////////
  2. //TITULO: CONTROL DE 8 SERVOMOTORES PARA HITEC                            //////
  3. //AUTOR: illusionista_86                                                      //////
  4. //FECHA: 20 - 04 - 11                                                                     //////
  5. //DESCRIPCION: POR MEDIO DEL PROGRAMA CONTROL DE 8 SERVOS.EXE //////
  6. //                         CONTROLARAS POR MEDIO DE BARRAS QUE TE INDICARA//////
  7. //                         EL GRADO Y EL SERVO A CONTROLAR.               //////
  8. ////////////////////////////////////////////////////////////////////
  9. ////////////////////////////////////////////////////////////////////
  10.  
  11. #include<16F628A.H>
  12. #include <string.h>
  13. #fuses HS,NOWDT,NOLVP,MCLR,NOPROTECT
  14.  
  15. //HS: CRISTAL DE HIGH SPEED 20MHZ
  16. //NOWDT: NO SE UTILIZA EL PERRO GUARDIAN
  17. //NOLVP: SE DESACTIVA ESTA OPCION DE PROGRAMACION
  18. //MCLR:ACTIVAMOS EL MASTER CLEAN
  19. //NOPROTECT: NO SE PROTEGE EL CODIGO()
  20.  
  21. #use delay(clock=20000000)                      //CRISTAL DE 20MHZ
  22. #use rs232(uart1,baud=9600,parity=N,bits=8,stop=1)                      //PIN_B1->RX,PIN_B2->TX
  23. //#use rs232(uart1,baud=9600)
  24. #use fast_io(A)                                         //RAPIDA INTERVENCION DEL PUERTO A
  25. #use fast_io(B)                                         // ''          ''         PUERTO B
  26. #priority timer1,rda                            //Es mas primordial que se atienda la interrupcion
  27.                                                                         //en el timer1
  28. //CONSTANTES DE ENCENDIDO
  29.  
  30. int MODO=10;
  31. unsigned int baudrate_config=7;
  32. //VARIABLES A CONTROLAR
  33.  
  34. unsigned long tick;                     //E
  35. unsigned int servo=0;           //ES EL NUMERO DEL SERVO A CONTRLAR MAXIMO CONTAR DE 0 A 7
  36.  
  37. short FLAG=0;                           //ACTUALIZADOR
  38. unsigned int NSERVO=0;          //NUMERO DE SERVO SELECCIONADO
  39. unsigned int i;
  40. int ini=0;
  41. unsigned int pos2[]={0,0,0,0,0,0,0,0,0,0};
  42. //VARIABLE DE CONTROL DE PULSO DE ALTO Y BAJO PARA LOS 8 SERVOS
  43. //COLOCADO COMO UN ARREGLO
  44.  
  45. unsigned long T_ON[]={0,0,0,0,0,0,0,0},T_OFF=0;
  46. float ms_ton[]={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
  47. float ms_toff=0;
  48.  
  49.  
  50. void config(void){
  51.  
  52.                 output_a(0x00);
  53.                 output_b(0x00);
  54.                 set_tris_a(0xA0);
  55.                 set_tris_b(0x02);
  56.                 //output_bit(PIN_B3,1);
  57.                 setup_comparator(NC_NC_NC_NC);                  //Comparadores APAGADO
  58.                 setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //Tick de 0.0002ms
  59.                 set_timer1(tick);
  60.                 disable_interrupts(INT_TIMER1);
  61.                 disable_interrupts(INT_RDA);
  62.                 disable_interrupts(GLOBAL);
  63. }
  64.  
  65.  
  66. void calc_tiempos(int grados[]){
  67.  
  68.     ms_toff=20.0;
  69.     //((2.5-0.5)/(180.0-0.0))
  70.     for (int i=0;i<8;i++){
  71.         ms_ton[i]=0.01111*(float)grados[i]+0.5;
  72.         ms_toff=ms_toff-ms_ton[i];
  73.         T_ON[i]=65536-(unsigned long)((ms_ton[i]/1000.0)*5000000.0); // 62556
  74.     }
  75.     T_OFF=65536-(unsigned long)((ms_toff/1000.0)*5000000.0); // 28516
  76.  
  77. }
  78.  
  79. #INT_RDA
  80. void Interrupcion_X_recepcion(void){
  81.  
  82.                 //disable_interrupts(INT_TIMER1);//DESACTIVA EL TIMER 1
  83.                 if(kbhit()){                                    //HAY INFORMACION A CAPTAR
  84.  
  85.                         MODO=getc();
  86.  
  87.                         if (MODO==0){
  88.                                         //enable_interrupts(INT_TIMER1);
  89.                         }else if(MODO==1){
  90.  
  91.                                         pos2[0]=getc();
  92.                                         pos2[1]=getc();
  93.                                         pos2[2]=getc();
  94.                                         pos2[3]=getc();
  95.                                         pos2[4]=getc();
  96.                                         pos2[5]=getc();
  97.                                         pos2[6]=getc();
  98.                                         pos2[7]=getc();
  99.  
  100.                         }else if(MODO==2){
  101.                             output_toggle(PIN_B3);
  102.                                         NSERVO=getc();
  103.                                         pos2[NSERVO-1]=getc();
  104.  
  105.                         }else if (MODO==3){
  106.                                         NSERVO=getc();
  107.                         }else if (MODO==4){
  108.                                 baudrate_config=getc();
  109.                         }
  110.                 }
  111.                 FLAG=1; //ESTE PARAMETRO TE INDICA QUE SE A EFECTUADO UN CAMBIO EN UN DE LOS
  112.                                 //SERVOMOTORES
  113.                                                                                         //PARA QUE SIGA DONDE SE QUEDO...
  114. }
  115.  
  116. void config_baud_uart(unsigned int baudrate){
  117.  
  118.  
  119.         switch (baudrate)
  120.         {
  121.                 case 0: set_uart_speed(1200);
  122.                                 break;
  123.                 case 1: set_uart_speed(2400);
  124.                                 break;
  125.                 case 2: set_uart_speed(4800);
  126.                                 break;
  127.                 case 3: set_uart_speed(9600);
  128.                                 break;
  129.                 case 4: set_uart_speed(19200);
  130.                                 break;
  131.                 case 5: set_uart_speed(38400);
  132.                                 break;
  133.                 case 6: set_uart_speed(57600);
  134.                                 break;
  135.                 case 7: set_uart_speed(115200);
  136.                                 break;
  137.         }
  138.  
  139. }
  140.  
  141. void set_servos(int s1,int s2, int s3, int s4, int s5, int s6, int s7, int s8){
  142.     output_bit(PIN_A0,s1);output_bit(PIN_A1,s2);output_bit(PIN_A2,s3);output_bit(PIN_A3,s4);
  143.     output_bit(PIN_B4,s5);output_bit(PIN_B5,s6);output_bit(PIN_B6,s7);output_bit(PIN_B7,s8);
  144.     set_timer1(T_ON[servo]);
  145. }
  146.  
  147. #INT_TIMER1
  148. void Interrupcion_timer1(void){
  149.  
  150.         if (servo==0){
  151.             set_servos(1,0,0,0,0,0,0,0);
  152.             servo=1;
  153.         }else if(servo==1){
  154.             set_servos(0,1,0,0,0,0,0,0);
  155.             servo=2;
  156.         }else if(servo==2){
  157.             set_servos(0,0,1,0,0,0,0,0);
  158.             servo=3;
  159.         }else if(servo==3){
  160.             set_servos(0,0,0,1,0,0,0,0);
  161.             servo=4;
  162.         }else if(servo==4){
  163.             set_servos(0,0,0,0,1,0,0,0);
  164.             servo=5;
  165.         }else if(servo==5){
  166.             set_servos(0,0,0,0,0,1,0,0);
  167.             servo=6;
  168.         }else if(servo==6){
  169.             set_servos(0,0,0,0,0,0,1,0);
  170.             servo=7;
  171.         }else if(servo==7){
  172.             set_servos(0,0,0,0,0,0,0,1);
  173.             servo=8;
  174.         }else if(servo==8){
  175.             output_bit(PIN_A0,0);output_bit(PIN_A1,0);output_bit(PIN_A2,0);output_bit(PIN_A3,0);
  176.             output_bit(PIN_B4,0);output_bit(PIN_B5,0);output_bit(PIN_B6,0);output_bit(PIN_B7,0);
  177.             set_timer1(T_OFF);
  178.         }                               //ESTABLECE EL TIMER PARA MANTENER EL PUSLO ALTO
  179.                                                                                 //O BAJO PARA EL PIN QUE CORRESPONDA
  180. }
  181.  
  182.  
  183. void main(void){
  184.  
  185.     config();
  186.     output_bit(PIN_B3,1);
  187.     enable_interrupts(GLOBAL);
  188.     enable_interrupts(INT_RDA);
  189.  
  190.     while(TRUE){
  191.  
  192.         delay_ms(50);
  193.  
  194.         if (FLAG==1){
  195.             if (MODO==1){
  196.                     output_bit(PIN_B3,1);
  197.                     for(int i=0;i<=7;i++){
  198.                             printf("%u\n",pos2[i]);
  199.                     }
  200.                     calc_tiempos(pos2);
  201.                     if (ini==0){
  202.                             enable_interrupts(INT_TIMER1);
  203.                             ini=1;
  204.                     }
  205.             }else if (MODO==2){
  206.                 output_toggle(PIN_B0);
  207.                     printf("%u\n",MODO);
  208.                     printf("%u\n",NSERVO);
  209.                     printf("%u\n",pos2[NSERVO-1]);
  210.                     calc_tiempos(pos2);
  211.             }else if (MODO==3){
  212.                     printf("%u\n",MODO);
  213.                     printf("%u\n",NSERVO);
  214.                     printf("%u\n",pos2[NSERVO-1]);
  215.  
  216.             }else if (MODO==4){
  217.                     printf("%u\n",baudrate_config);
  218.                     config_baud_uart(baudrate_config);
  219.             }
  220.             FLAG=0;MODO=10;
  221.         }
  222.  
  223.     }
  224. }

en el siguiente enlace se encuentra la aplicacion en cuestion para ser instalada, el proyecto en mplabX utilizando CCS, y el archivo proteus para silumar, y el esquematico de la placa realizada para tal fin.


https://www.dropbox.com/sh/9syipx78rjcmbj2/AACtP84Yz9OSzsaIS3wGoC7ua?dl=0

adjunto una imagen de la aplicacion.


PD: perdon por los acentos, estoy utilizando un teclado de EEUU que no los llevan (o no se como ponerlos, jejej)

« Última modificación: 23 de Octubre de 2014, 12:18:06 por illusionista_86 »

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Mini curso "Programación en XC8"
« Respuesta #282 en: 24 de Octubre de 2014, 19:55:51 »
Sigo sin lograr hacer funcionar el Lcd y no soy capaz de dar con el error, si alguien fuera tan amable de revisar el código lo agradecería, el problema es que no consigo visualizar nada en el Lcd.
El Lcd esta conectado de la siguiente manera:
RB3  ---->  E
RB2  ---->  RS
RB4  ---->  D4
RB5  ---->  D5
RB6  ---->  D6
RB7  ---->  D7

my_xlcd
Código: [Seleccionar]
#ifndef __XLCD_H
#define __XLCD_H
#include "p18f2550.h"
/* PIC18 XLCD peripheral routines.
 *
 *   Notes:
 *      - These libraries routines are written to support the
 *        Hitachi HD44780 LCD controller.
 *      - The user must define the following items:
 *          - The LCD interface type (4- or 8-bits)
 *          - If 4-bit mode
 *              - whether using the upper or lower nibble
 *          - The data port
 *              - The tris register for data port
 *              - The control signal ports and pins
 *              - The control signal port tris and pins
 *          - The user must provide three delay routines:
 *              - DelayFor18TCY() provides a 18 Tcy delay
 *              - DelayPORXLCD() provides at least 15ms delay
 *              - DelayXLCD() provides at least 5ms delay
 */

/* Interface type 8-bit or 4-bit
 * For 8-bit operation uncomment the #define BIT8
 */
/* #define BIT8 */

/* When in 4-bit interface define if the data is in the upper
 * or lower nibble.  For lower nibble, comment the #define UPPER
 */
 //#define UPPER

/* DATA_PORT defines the port to which the LCD data lines are connected */
 #define DATA_PORT       PORTB
 #define TRIS_DATA_PORT TRISB

/* CTRL_PORT defines the port where the control lines are connected.
 * These are just samples, change to match your application.
 */
 #define RW_PIN   LATBbits.LATB1   /* PORT for RW */
 #define TRIS_RW  TRISBbits.TRISB1     /* TRIS for RW */

 #define RS_PIN   LATBbits.LATB2   /* PORT for RS */
 #define TRIS_RS  TRISBbits.TRISB2     /* TRIS for RS */

 #define E_PIN    LATBbits.LATB3   /* PORT for D  */
 #define TRIS_E   TRISBbits.TRISB3     /* TRIS for E  */

/* Display ON/OFF Control defines */
#define DON         0b00001111  /* Display on      */
#define DOFF        0b00001011  /* Display off     */
#define CURSOR_ON   0b00001111  /* Cursor on       */
#define CURSOR_OFF  0b00001101  /* Cursor off      */
#define BLINK_ON    0b00001111  /* Cursor Blink    */
#define BLINK_OFF   0b00001110  /* Cursor No Blink */

/* Cursor or Display Shift defines */
#define SHIFT_CUR_LEFT    0b00000100  /* Cursor shifts to the left   */
#define SHIFT_CUR_RIGHT   0b00000101  /* Cursor shifts to the right  */
#define SHIFT_DISP_LEFT   0b00000110  /* Display shifts to the left  */
#define SHIFT_DISP_RIGHT  0b00000111  /* Display shifts to the right */

/* Function Set defines */
#define FOUR_BIT   0b00101100  /* 4-bit Interface               */
#define EIGHT_BIT  0b00111100  /* 8-bit Interface               */
#define LINE_5X7   0b00110000  /* 5x7 characters, single line   */
#define LINE_5X10  0b00110100  /* 5x10 characters               */
#define LINES_5X7  0b00111000  /* 5x7 characters, multiple line */

#ifdef _OMNI_CODE_
#define PARAM_SCLASS
#else
#define PARAM_SCLASS auto
#endif

#ifndef MEM_MODEL
#ifdef _OMNI_CODE_
#define MEM_MODEL
#else
#define MEM_MODEL far  /* Change this to near for small memory model */
#endif
#endif

/* OpenXLCD
 * Configures I/O pins for external LCD
 */
void OpenXLCD(PARAM_SCLASS unsigned char);

/* SetCGRamAddr
 * Sets the character generator address
 */
void SetCGRamAddr(PARAM_SCLASS unsigned char);

/* SetDDRamAddr
 * Sets the display data address
 */
void SetDDRamAddr(PARAM_SCLASS unsigned char);

/* BusyXLCD
 * Returns the busy status of the LCD
 */
unsigned char BusyXLCD(void);

/* ReadAddrXLCD
 * Reads the current address
 */
unsigned char ReadAddrXLCD(void);

/* ReadDataXLCD
 * Reads a byte of data
 */
char ReadDataXLCD(void);

/* WriteCmdXLCD
 * Writes a command to the LCD
 */
void WriteCmdXLCD(PARAM_SCLASS unsigned char);

/* WriteDataXLCD
 * Writes a data byte to the LCD
 */
void WriteDataXLCD(PARAM_SCLASS char);

/* putcXLCD
 * A putc is a write
 */
#define putcXLCD WriteDataXLCD

/* putsXLCD
 * Writes a string of characters to the LCD
 */
void putsXLCD(PARAM_SCLASS char *);

/* putrsXLCD
 * Writes a string of characters in ROM to the LCD
 */
void putrsXLCD(const char *);

/* User defines these routines according to the oscillator frequency */
extern void DelayFor18TCY(void);
extern void DelayPORXLCD(void);
extern void DelayXLCD(void);

#endif
He probado dejando comentado //#define UPPER y sin comentar y no funciona

main
Código: [Seleccionar]
#include <xc.h>                 //PIC hardware mapping
#include <plib/delays.h>
#include "my_xlcd.h"
#include <stdlib.h>
#include <stdio.h>

#define _XTAL_FREQ  48000000        //Used by the XC8 delay_ms(x) macro

// CONFIG1L
#pragma config PLLDIV = 5       // PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))
#pragma config CPUDIV = OSC1_PLL2// System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
#pragma config USBDIV = 1       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)

// CONFIG1H
#pragma config FOSC = HSPLL_HS     // Oscillator Selection bits (XT oscillator (XT))
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOR = ON         // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 3         // Brown-out Reset Voltage bits (Minimum setting)
#pragma config VREGEN = OFF     // USB Voltage Regulator Enable bit (USB voltage regulator disabled)

// CONFIG2H
#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3H
#pragma config CCP2MX = ON      // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF     // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
#pragma config LPT1OSC = OFF    // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON       // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF        // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM is not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)

/* Retardos requeridos por la libreria XLCD */
void DelayFor18TCY(void);
void DelayPORXLCD(void);
void DelayXLCD(void);

//*********************************************************
/* FUNCIONES DE RETARDOS REQUERIDOS POR LA LIBRERIA LCD  */
//*********************************************************
void DelayFor18TCY(void)
{
    Delay10KTCYx(120);      /* Retardo de 18 TCY */
    return;
}
void DelayPORXLCD(void)
{
    Delay1KTCYx(180);       /* Retardo de 15ms */
    return;
}
void DelayXLCD(void)
{
    Delay1KTCYx(60);        /* Retardo de 5ms */
    return;
}


//*********************************************************
/* FUNCION PRINCIPAL */
//*********************************************************

int main ()
{
    /* Set RB<4:0> as digital I/O pins (required if config bit PBADEN is set */
    ADCON1 = 0x0E;
    /* Configure external LCD */
    OpenXLCD( FOUR_BIT & LINES_5X7 );
    /* Esperamos a que el display este disponible */
    while(BusyXLCD());
    WriteCmdXLCD( BLINK_ON );
    WriteCmdXLCD( SHIFT_DISP_LEFT );
     while(1)
     {
     //Primera línea
     SetDDRamAddr(0x00);
     putrsXLCD("HOLA");
     //Segunda línea
     SetDDRamAddr(0x40);
     putrsXLCD("MUNDO");
     }
}

Gracias.
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Mini curso "Programación en XC8"
« Respuesta #283 en: 26 de Octubre de 2014, 16:19:36 »
Me doy por vencido despues de 12 dias intentando visualizar hola en el lcd, otro de tantos a la basura.

Miquel_S
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Mini curso "Programación en XC8"
« Respuesta #284 en: 26 de Octubre de 2014, 16:28:00 »
Antes de tirar la Pcb a la basura es necesario tener el pin RW conectado al micro o puedo ponerlo directo a masa como es el caso.
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.