اطلاعیه

Collapse
No announcement yet.

مشکل در برنامه تست کریستال

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    مشکل در برنامه تست کریستال

    سلام
    من یه برنامه برای تست کریستال پیدا کردم
    اما نمیتونم شبیه سازیش کنم
    اینجا برنامه شو میذارم ممنون میشم اگه کمکم کنین
    مشکلم اینه که نمیدونم چه پایه هایی به 7 سگمنت وصل میشه

    کد:
    #include <16F83.H>
    
    #fuses xt		// Use Xtal clock
    #fuses nowdt		// No watchdog timer
    #fuses noprotect
    #fuses put		// Power up timer
    
    #define discl pin_b4	// Display clock. Pin 10 of the pic
    #define disda pin_b5	// Display data. Pin 11 of the pic
    #define block pin_a3	// Used to block input pulses. Pic pin 2 to pin 3
    
    #byte tmr0 = 1
    #byte porta = 5
    #byte portb = 6
    #byte option = 0x81
    
    #use fast_io(a)
    #use fast_io(b)
    
    char to7seg[10] = {		// 7 segment decode for TSM6734
    /*0 */	0b11111100,
    /*1 */	0b01100000,
    /*2 */	0b11011010,
    /*3 */	0b11110010,
    /*4 */	0b01100110,
    /*5 */	0b10110110,
    /*6 */	0b10111110,
    /*7 */	0b11100000,
    /*8 */	0b11111110,
    /*9 */	0b11110110
    };
    
    char prescaler_cnt;
    char cnt;
    char dispbuf[5];		// 4 digit number to display
    long count, x;
    
    // Local function prototypes
    void send_clk(void);		// For the display
    void send8(byte number);	// For the display
    void sprintf(byte x);		// For converting the count to ASCII decimal
    void display(char led);
    
    //---------------------------------------------------------------------------
    // This function receives the output of the printf() function in ascii and
    // stores it in dispbuf[] after changing to binary
    //---------------------------------------------------------------------------
    void sprintf(byte x)
    {
     dispbuf[cnt] = x - '0';	// Store the number as binary
     cnt++;			// Increment the index for the next number
    }
    //---------------------------------------------------------------------------
    // Clocks the TSM6734 display
    //---------------------------------------------------------------------------
    void send_clk(void)
    {
     output_high(discl);
     output_low(discl);
    }
    //---------------------------------------------------------------------------
    // Sends the 8 bits to the TSM6734 display one bit at a time by shitfing the
    // bits into lsb and loading the bits into disda. MS bit is sent first.
    //---------------------------------------------------------------------------
    void send8(byte number)
    {
     for(cnt=0; cnt<8; cnt++)			// 8 bits to send
     {
      output_bit(disda, (number >> (7-cnt)) & 1);	// Send MS bit first
      send_clk();
     }
    }
    //---------------------------------------------------------------------------
    // This initialises and clears the display
    //---------------------------------------------------------------------------
    void init_display(void)
    {
     output_low(disda);		// Take display data low
     for(cnt=0; cnt<40; cnt++)
      send_clk();			// Clear the display
    }
    //---------------------------------------------------------------------------
    // Send the 4 digits in the display buffer dispbuf to the TSM6734 after
    // converting each digit to the 7 segment code and adding a decimal point.
    // If the passed parameter 'led' is non zero, the external led attached to
    // pin 1 of the display will be turned on. If pin 6 of the PIC is shorted to
    // pin 5 (gnd) TSM6734 type display is used. If pin 6 is linked to pin 7
    // which is programmed to be high, Farnell display is used. Chech the status
    // of pin 6 to determine which type of display to drive.
    //---------------------------------------------------------------------------
    void display(char led)
    {
     output_high(disda);			// Data start bit for the display
     send_clk();
    
     output_high(pin_b1);
     if(input(pin_b0))			// Jumper for Farnell 948-536 display
     {
      send8(to7seg[dispbuf[3]]);
      send8(to7seg[dispbuf[2]]);
      send8(to7seg[dispbuf[1]]);
      send8(to7seg[dispbuf[0]]);
     }
     else					// No jumper, TSM6734 display
     {
      send8(to7seg[dispbuf[0]] + 1);	// Add decimal point
      send8(to7seg[dispbuf[1]]);
      send8(to7seg[dispbuf[2]]);
      send8(to7seg[dispbuf[3]]);
     }
    
     if(led)
      send8(0b10000000);			// External led 1 ON
     else
      send8(0);				// External leds off
    }
    //============================= M A I N ================================
    void main()
    {
     set_tris_b(0b00000001);	// Set up Port b. All output except bit 0
     portb = 0b00000001;
     set_tris_a(0b11111111);	// Set up Port a. All input
    
     init_display();		// Ensure we start on the right foot
    
    // Set up tmr0 as counter with prescaler of 256
     option = 0b11100111;		// Start timer / counter
    
     while(1)			// Loop forever
     {
      tmr0 = 0;			// Reset count in tmr0 and the prescaler
      set_tris_a(0b11111111);	// RA3 is now input. Start counting
    
    // 1 mS delay. We can't use the onboard timer TIM0 because it is used in
    // counter mode with a prescaler to count the incoming pulses.
    // To measure a frequency of 6 MHz and display as 4 digits, we need to gate
    // the incoming pulses 1000 times slower than 6 Mhz so that 6000000 counts
    // are measured as 6000. This effectively divides the frequency by 1000.
    
      for(x=0; x<82; x++)		// 1 mS delay with 4 MHz CPU clock
       {;}
    // Extra delay to make it exactly 1 mS
      portb = 0b00000000;		// 1 cycle
      portb = 0b00000000;
      portb = 0b00000000;
      portb = 0b00000000;
    
    // 1 mS is up. Stop the incoming pulses from reaching the TOCKI pin by making
    // pin 2 output (Ra3) and switching it to LOW. This shorts the counter's input
    // to gnd, preventing the counter from counting. A 4K7 series resistor is used
    // at the input so that the input can be grounded safely.
    
      set_tris_a(0b11110111);	// RA3 is now output
      output_low(block);		// Stop counting
    
    // We must now get the count in tmr0 and the prescaler and add them.
    // The total count will be 256 * tmr0 + prescaler. The prescaler can not be
    // read directly. To get the count in the prescaler we clock the input pin
    // using RA3 until the prescaler overflows and increments tmr0. The number of
    // pulses needed to overflow the prescaler is the prescaler value.
    // This will increment tmr0 so we must not forget to decrement tmr0 afterwards
    
      cnt = tmr0;				// Get the value in tmr0
      prescaler_cnt = 0;
      while(cnt == tmr0)			// Loop till tmr0 increments
      {
       output_high(block);		// Keep clocking the input pin, hi/low
       output_low(block);
       prescaler_cnt++;
      }
      prescaler_cnt = 256 - prescaler_cnt;
      tmr0 -= 1;				// Remember to decrement tmr0
    
      count = tmr0 * 256 + prescaler_cnt;
      cnt = 0;				// Zero the index before printf()
      printf(sprintf, "%04ld", count);	// Convert count to 4 digit decimal
    
      if(count > 0 && count < 10000)
       display(0);			// and display the count
    
    // Delay for display update and flash the led to show it's working
      display(0);			// Turn off the led
      for(x=0; x<8200; x++) ;	// 0.1 Sec delay
    
      if(count > 0 && count < 10000)
      {
       display(1);		// Turn on the led
       for(x=0; x<8200; x++) ;	// 0.1 Sec delay
      }
     }
    }

    #2
    پاسخ : مشکل در برنامه تست کریستال

    شما باید از آی سی واسط TSM6734 استفاده کنین
    پایه ها هم اینجا تعریف شدن




    #define discl pin_b4 // Display clock. Pin 10 of the pic
    #define disda pin_b5 // Display data. Pin 11 of the pic
    [glow=red,2,300]تاپيک هاي ايجاد شده[/glow]

    دیدگاه

    لطفا صبر کنید...
    X