Menu

Help needed translate code C to Pyastra

Help
None
2006-09-01
2013-04-25
  • None

    None - 2006-09-01

    like translate the following code to Pyastra. Pardon by my English 

    # // ----- PORTD bits --------------------
    # typedef union {
    #   struct {
    #     unsigned char :1;
    #     unsigned char :1;
    #     unsigned char :1;
    #     unsigned char :1;
    #     unsigned char LED0:1;
    #     unsigned char :1;
    #     unsigned char :1;
    #     unsigned char :1;
    #   };
    # } __PORTD_bits_t;
    # extern volatile __PORTD_bits_t __at(PORTD_ADDR) PORTD_bits;
    #
    # #define LED0               PORTD_bits.LED0
    #
    # void main()
    # {
    #         TRISD = 0;
    #     LED0  = 1;    //this line doesnt work...
    #
    #         while(1) {};
    # }

     
    • Alex Zyranov

      Alex Zyranov - 2006-09-04

      If I correctly understand your code (i'm not very familiar with C), then Pyastra equivalent would be:

      TRISD = 0
      PORTD = fbin('1111 1111')
      PORTD[4] = 1

      The first line doesn't require any comments. The second line sets all the port D bits to "1". fbin pseudo function denotes binary data. Third line sets bit 4 of port D. The infinite loop is set by Pyastra automatically at the end of any program.

       

Log in to post a comment.