⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 samplecereb.c

📁 example of communication between the Cerebellum 16f877 pic board and the CMUcam
💻 C
字号:
// This is Version 4 of cereb //
/* Change made:
Servo mask now enables partial servo usage (and partial digital output usage)
Button1 moved to pin 0 and motor direction moved to pin 1.
Added i2c support (not demonstrated by this sample code)

*/

#include "cerebv41.h" // load declarations
#include "cerebv41.c" // load useful cerebellum functions



int postest = 100;

// sample that blinks one LED and blinks the other when a button is held down //
// it also tells you over serial what you type in (1 char at a time) and 
// moves a servo on D1 when the button is held down, one step at a time.
void button_sample(void)
{
 char inc;
 while (1) {
   if (PORTB & BTN2) // if button2 is depressed
   {
	set_bit(PORTB, GREEN); // turn on green led
	inc = ser_rcv_nb(); // non-blocking serial port receive
	ser_putstring("\n\rReceived: ");
	if (inc == 0) {
		ser_putstring("nothing to read...");
	} else {
		ser_tx(inc);
	}
	ser_putstring("\n\rEnd1");
	
	postest--;
	servo_pos[1] = postest; // re-position servo by 1
	inc = adc_read(7);      // read analog input 7 (E2)
	ser_putstring("ADC7 read: ");
	ser_writechar(inc);
	ser_putstring("\n\rEnd2\n\r");	 	
   } // end if button2 depressed
   set_bit(PORTB, YELLOW); // turn on yellow led
   delay_ms( 250 );
   clear_bit(PORTB, YELLOW); // turn off both led's
   clear_bit(PORTB, GREEN);
   delay_ms( 250 );
   
 } // end while

} // end button_sample() //

void main(void)
{
	init_cerebellum(); // configure cerebellum
	ser_init(SER_115200); // start up serial port handling
	ser_putstring("\n\rWelcome to Cerebellum!\n\r");
	servo_init(); // start up servo control
	servo_state = 1;
	set_bit(INTCON, GIE); // start up interrupts- required for servo control
	servo_mask = 11111111b; // set up all D0-D7 pins for servo control

	servo_pos[1] = postest; // take servo 1 to position 100  //

	ADCON1 = 0; // initialize analog-digital converter //

	pwm_init(); // initialize pwm motor output

      button_sample();

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -