This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Trying to transmit with interrupt in XC164CS

Hi everybody,
I am learning to program with MCUs and now i have got the SK-XC164 board.I am trying to transmit via ASC0 a message. This message has 6 equal bytes and I must do it with transmit interrupt. Has anyone a simple program to practise??. The message I would like to see the message through Hyperterminal on PC. Thanks to everyone.

Parents
  • This is my code (@ -> BYTE (Unsigned char))

    #include <AR166.h>
    #include <XC164.h>
    #include "NewType.h"
    #include "Central.h"
    
    #define TASK1      1
    
    void    InitHardware                    (void);
    void    CCU6_vInit                              (void);
    void    Init_P9                                 (void);
    void    ASC0_vInit                              (void);
    
    
    OS_TID id1;
    
    void main (void)
    {
            InitHardware();
            os_sys_init (TASK1);
    }
    
    /////////////////////////////////////////////////////////////////////////////////////
    void    InitHardware                    (void)
    {
       //CCU6_vInit();    // initializes the Capture / Compare Unit 6 (CCU6)
       Init_P9();
       ASC0_vInit();
       PSW_IEN        =  1; //   globally enable interrupts
    }
    /////////////////////////////////////////////////////////////////////////////////////
    
    /////////////////////////////////////////////////////////////////////////////////////
    void    Init_P9                                 (void)
    {
      ODP9           =  0x0000;      // load open-drain register
      P9             =  0x0000;      // load data register
      ALTSEL0P9      =  0x0000;      // load alternate output function select
                                     // register 0
      ALTSEL1P9      =  0x0000;      // load alternate output function select
                                     // register 1
      POCON9         =  0x0000;      // load output control register
      DP9            =  0x0010;      // load direction register
    }
    /////////////////////////////////////////////////////////////////////////////////////
    void            ASC0_vInit                      (void)
    {
      ///  -----------------------------------------------------------------------
      ///  Configuration of the ASC0 Baudrate Generator:
      ///  -----------------------------------------------------------------------
      ///  - additionally reduce serial clock to 2
      ///  - required baud rate = 19,200 kbaud
      ///  - real baud rate     = 19,200 kbaud
      ///  - deviation          = 0,000 %
    
      ASC0_BG        =  0x0011;      // load ASC0 baud rate time reload register
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the ASC0 Operation Mode:
      ///  -----------------------------------------------------------------------
      ///  - 8-bit data asychronous operation with one stop bit
      ///  - receiver is enabled
    
      ASC0_CON       =  0x0011;      // load ASC0 control register
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the used ASC0 Port Pins:
      ///  -----------------------------------------------------------------------
      ///  - P3.10 is used for ASC0 Transmit Data Output (TxDA0)
      ///  - P3.11 is used for ASC0 Receive data Input (RxDA0)
    
      ALTSEL0P3     |=  0x0400;      // select alternate output function
      P3   |= 0x0400;    //set data register
      DP3  |= 0x0400;    //set direction register
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the used ASC0 Interrupts:
      ///  -----------------------------------------------------------------------
      ///  Tx service request node configuration:
      ///  - Tx interrupt priority level (ILVL) = 14
      ///  - Tx interrupt group level (GLVL) = 1
      ///  - Tx group priority extension (GPX) = 0
    
      ASC0_TIC       =  0x0080;
    
      ///  Use PEC channel 1 for ASC0 Tx INT:
      ///  - normal interrupt
      ///  - pointers are not modified
      ///  - transfer a word
      ///  - service End of PEC interrrupt by a EOP interrupt node is disabled
      ///  - channel link mode is disabled
    
      PECC1          =  0x0000;      // load PECC1 control register
    
    
      ///  TxBuffer service request node configuration:
      //// - TxBuffer interrupt is enabled but NO INTERRUPT WILL BE GENERATED
      ////   because priority level is 0
    
      ASC0_TBIC      =  0x0040;
    
      ///  Rx service request node configuration:
      ///  - Rx interrupt priority level (ILVL) = 15
      ///  - Rx interrupt group level (GLVL) = 1
      ///  - Rx group priority extension (GPX) = 0
    
      ASC0_RIC       =  0x007D;
    
      ///  Use PEC channel 5 for ASC0 Rx INT:
      ///  - normal interrupt
      ///  - pointers are not modified
      ///  - transfer a word
      ///  - service End of PEC interrrupt by a EOP interrupt node is disabled
      ///  - channel link mode is disabled
    
      PECC5          =  0x0000;      // load PECC5 control register
      ASC0_CON      |=  0x8000;      // enable baud rate generator
    }
    /////////////////////////////////////////////////////////////////////////////////////
    void TASK_1 (void) _task_       TASK1
    {
                    id1 = os_tsk_self ();
                    ASC0_TBUF = '@';
    
    }
    /////////////////////////////////////////////////////////////////////////////////////
    void ASC0_viTx(void) interrupt ASC0_TINT
    {
    int     i;
            for (i=0; i<6; i++)
            {
                    ASC0_TBUF = '@';
            }
    }
    

Reply
  • This is my code (@ -> BYTE (Unsigned char))

    #include <AR166.h>
    #include <XC164.h>
    #include "NewType.h"
    #include "Central.h"
    
    #define TASK1      1
    
    void    InitHardware                    (void);
    void    CCU6_vInit                              (void);
    void    Init_P9                                 (void);
    void    ASC0_vInit                              (void);
    
    
    OS_TID id1;
    
    void main (void)
    {
            InitHardware();
            os_sys_init (TASK1);
    }
    
    /////////////////////////////////////////////////////////////////////////////////////
    void    InitHardware                    (void)
    {
       //CCU6_vInit();    // initializes the Capture / Compare Unit 6 (CCU6)
       Init_P9();
       ASC0_vInit();
       PSW_IEN        =  1; //   globally enable interrupts
    }
    /////////////////////////////////////////////////////////////////////////////////////
    
    /////////////////////////////////////////////////////////////////////////////////////
    void    Init_P9                                 (void)
    {
      ODP9           =  0x0000;      // load open-drain register
      P9             =  0x0000;      // load data register
      ALTSEL0P9      =  0x0000;      // load alternate output function select
                                     // register 0
      ALTSEL1P9      =  0x0000;      // load alternate output function select
                                     // register 1
      POCON9         =  0x0000;      // load output control register
      DP9            =  0x0010;      // load direction register
    }
    /////////////////////////////////////////////////////////////////////////////////////
    void            ASC0_vInit                      (void)
    {
      ///  -----------------------------------------------------------------------
      ///  Configuration of the ASC0 Baudrate Generator:
      ///  -----------------------------------------------------------------------
      ///  - additionally reduce serial clock to 2
      ///  - required baud rate = 19,200 kbaud
      ///  - real baud rate     = 19,200 kbaud
      ///  - deviation          = 0,000 %
    
      ASC0_BG        =  0x0011;      // load ASC0 baud rate time reload register
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the ASC0 Operation Mode:
      ///  -----------------------------------------------------------------------
      ///  - 8-bit data asychronous operation with one stop bit
      ///  - receiver is enabled
    
      ASC0_CON       =  0x0011;      // load ASC0 control register
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the used ASC0 Port Pins:
      ///  -----------------------------------------------------------------------
      ///  - P3.10 is used for ASC0 Transmit Data Output (TxDA0)
      ///  - P3.11 is used for ASC0 Receive data Input (RxDA0)
    
      ALTSEL0P3     |=  0x0400;      // select alternate output function
      P3   |= 0x0400;    //set data register
      DP3  |= 0x0400;    //set direction register
    
      ///  -----------------------------------------------------------------------
      ///  Configuration of the used ASC0 Interrupts:
      ///  -----------------------------------------------------------------------
      ///  Tx service request node configuration:
      ///  - Tx interrupt priority level (ILVL) = 14
      ///  - Tx interrupt group level (GLVL) = 1
      ///  - Tx group priority extension (GPX) = 0
    
      ASC0_TIC       =  0x0080;
    
      ///  Use PEC channel 1 for ASC0 Tx INT:
      ///  - normal interrupt
      ///  - pointers are not modified
      ///  - transfer a word
      ///  - service End of PEC interrrupt by a EOP interrupt node is disabled
      ///  - channel link mode is disabled
    
      PECC1          =  0x0000;      // load PECC1 control register
    
    
      ///  TxBuffer service request node configuration:
      //// - TxBuffer interrupt is enabled but NO INTERRUPT WILL BE GENERATED
      ////   because priority level is 0
    
      ASC0_TBIC      =  0x0040;
    
      ///  Rx service request node configuration:
      ///  - Rx interrupt priority level (ILVL) = 15
      ///  - Rx interrupt group level (GLVL) = 1
      ///  - Rx group priority extension (GPX) = 0
    
      ASC0_RIC       =  0x007D;
    
      ///  Use PEC channel 5 for ASC0 Rx INT:
      ///  - normal interrupt
      ///  - pointers are not modified
      ///  - transfer a word
      ///  - service End of PEC interrrupt by a EOP interrupt node is disabled
      ///  - channel link mode is disabled
    
      PECC5          =  0x0000;      // load PECC5 control register
      ASC0_CON      |=  0x8000;      // enable baud rate generator
    }
    /////////////////////////////////////////////////////////////////////////////////////
    void TASK_1 (void) _task_       TASK1
    {
                    id1 = os_tsk_self ();
                    ASC0_TBUF = '@';
    
    }
    /////////////////////////////////////////////////////////////////////////////////////
    void ASC0_viTx(void) interrupt ASC0_TINT
    {
    int     i;
            for (i=0; i<6; i++)
            {
                    ASC0_TBUF = '@';
            }
    }
    

Children