亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cerebv41.c

?? example of communication between the Cerebellum 16f877 pic board and the CMUcam
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* Version Information:



Newest version - version 4.1, added I2C master support, print long ints



Changes made by version 3- this has a change in 

ser_rcv_nonblock so that it deals with overflows and framing errors

correctly-- the old nonblock failed when overflows occurred, freezing up

the cerebellum on blocking serial receives thereafter



Changes made by Version 2:  For new Cerebellum in which Btn1 is connected to B0

and the motor direction is now B1 instead of B0.



*/



/* Cereb.c is the main helper file for Cerebellum Programming. 

   See the API for details of how to use this stuff.

	Much of original code is courtesy of Kwanjee Ng

	Illah Nourbakhsh 2002 ; 2003
	Rashmi Patel, Tom Lauwers 2003

*/



/* things to add later -illah- :







*/



// API provided for cereb //////////////////////

//

// call init_cerebellum() first in your main

// turn on an led with set_bit(PORTB, (GREEN|YELLOW)); turn off with clear_bit

// (PORTB & BTNn) is true if button n is depressed and false otherwise

//

// To output on a digital pin on portD, use set_bit(PORTD, n); where n is 0-7 (and clear_bit)

// These are the pins to generally use for digital output.

// But if you're using the Servoes, you will have to set the mask for the servoes

// appropriately so that you can preserve some of the pins for your own digital out

// purposes.  Read the Servoes section below.

// 

// call ser_init(SER_115200) to set up hardware serial port

// ser_tx(char c) sends a character out over the serial line

// ser_putstring(const char *text) writes a CONST string out the serial line

// ser_writechar(char c) writes out a character in decimal (good for debugging!)
// ser_writelong(long data) writes out a long readably out the serial port

// ser_rcv() is a blocking receive char call that returns a char

//		note that if the input buffer has overflowed it dumps the buffer

//		and continues waiting for a new character to return!

// ser_rcv_nb() is a nonblocking receive char call that returns a char

//          or if there is nothing waiting, returns a 0. Does NOT check for

//		frame error and overflow conditions!!!

// to save memory, if not using the serial port, don't call ser_init() and then

// don't use any of the above functions.

// 

// to use servoes, begin by calling servo_init() in your main.

// then before expecting servoes to get used make servo_state=1;

// servoes use interrupts, so make sure you're starting interrupts:

//		set_bit(INTCON, GIE);

// then command a servo by commanding servo_pos[n]=p. This will drive

// the servo on port Dn to position p.  If p is zero, it deactivates the servo.

// to save memory, if not using servoes don't call servo_init(), do not

// put "set_bit(INTCON, GIE);" in your code, and also

// go to cereb.c (this file) and find void interrupt(void) and comment out the line that

// calls do_servo().

//

// to use some lines as servoes and other portD lines for direct digital outputs, note

// the variable servo_mask.  This defaults to 11111111b, which means all pins

// on portD are configured for servo output use.  If you want to have D0,D1

// and D3 be servo pins and the rest controlled directly by you, using set_bit,

// then in Main() you would include the line: "servo_mask = 00000111b;"

// Then the servo controller would ignore pins D3 - D7 and you can set them

// as desired. For example you could set pin3 to be high: "set_bit(PORTD,3);"

// Note the tristate is still configuring ALL of portD for digital output (not input).

//

// to use the analog-digital input lines, first in main you must initialize

// with the command: ADCON1=0;

// to read analog input channel ch, use adc_read(ch) which returns a char

// ch should be 0-7 inclusive. numbering on cerebellum goes from A0 as channel

// zero, left-to-right and top-to-bottom, so that E2 is analog channel 7

//

// to use the motor PWM outputs, first call pwm_init() in your code.

// if both commands are in there, call ser_init() first. The motor command

// is pwm_setvel8(n,dir,duty) where n=0 or 1 (0 means Motor1 on Cerebellum

// and 1 means Motor2 on Cerebellum). dir is direction (0 or 1) and duty is

// a char, with 0 meaning off and 255 meaning full-on.

// To save memory, if you are not using motor PWM then comment out pwm_init() in

// main().

// // 

//

// to use the I2C functions you need to be aware of the order in which functions need

// to be called.  The function i2c_init() needs to be called first, and only once.  

// this function should be called at the beginning of the program after the other init

// functions.  In order to send or receive with i2c you need to first start i2c communication.

// After a certain amount of data is sent, you must then stop communication.  Therefore,

// in order to send, for example three characters, you must call the i2c functions in

// the following order:

// i2c_start();

// i2c_send(address);*

// i2c_send(char1);

// i2c_send(char2);

// i2c_send(char3);

// i2c_stop();

//

// *because i2c accepts multiple devices on the bus, you have to specify 

// address of the device before the rest of the characters are sent.  

//

// Receiving requires several more functions, because after each character that is received,

// you must send an acknowledgement, requiring you to call a special i2cack(); function.  

// HOWEVER, after the last byte is sent, you must send a special non-acknowledgement, and call

// i2c_nak(); instead of i2cack();  As an example, assume you expect three bytes from a device.

// You would call:

// i2c_start();

// i2c_send(address+1);*

// char1 = i2c_receive();

// i2c_ack();

// char2 = i2c_receive();

// i2c_ack();

// char3 = i2c_receive();

// i2c_nak();   !note the special nak function here

// i2c_stop();

//

// * In order to tell a device that you are accepting information instead of sending it, the i2c

// standard requires you to add 1 to that device's address.  Therefore, all i2c devices have

// even numbered addresses.

//

// If you wish to send data, and then receive data immediately after, you may substitute an 

// i2c_restart() command for the i2c_stop()/i2c_start() commands.  Please refer to the sample

// i2c program to see this implementation.
////////////////////

// 




// Below code is for implementing the hardware serial port //

char ser_tmp;

char SSPCON@0x14;

char SSPCON2@0x91;

char SSPADD@0x93;

char SSPSTAT@0x94;

char SSPBUF@0x13;

char PIR1@0x0c;

char PIE1@0x8c;

char TRISC@0x87;

char TRISD@0x88;

char TXSTA@0x98;

char RCSTA@0x18;

char SPBRG@0x99;

char RCREG@0x1a;

char TXREG@0x19;

char PORTD@0x08;

char myOption_Reg@0x81;



// call ser_init to initial hardware serial as: ser_init(SER_115200) //

void ser_init(char spbrg_val) {

	

	SSPCON = 0;

	PIR1 = 0;  // this ensures also RCIF = TXIF = 0;

	clear_bit(PIE1,5); //RCIE = 0;

	clear_bit(PIE1,4); //TXIE = 0;

	TRISC = TRISC | 0xC0; // setup TRISC for USART use

	SPBRG = spbrg_val;

    	TXSTA = 000100100b; // txen, brgh

	RCSTA = 010010000b; // spen and cren, the rest all off

	ser_tmp = RCREG; // flush the rx buffer

	ser_tmp = RCREG;

	ser_tmp = RCREG;

}



// low-level call to send a character serially.

void ser_tx(char c) {



	//wait for txif to go hi

	while(!(PIR1 & 16)); //while (!TXIF); 

	//disable_interrupt(GIE); //?

	TXREG = c;

	//enable_interrupt(GIE);  //?

}



void ser_putstring(const char* text) {

    char i = 0;

    while( text[i] != 0 )

        ser_tx( text[i++] ); 

}



// writes a character out the serial port as a 1-3 digit number



void ser_writechar(char data) {

  if(data >= 100)

    ser_tx( '0' + data/100 );

  if(data >= 10)

    ser_tx( '0' + (data%100)/10 );

  ser_tx( '0' + data%10 );

}



// write a long int out to the serial

void ser_writelong(long data){



  if(data >= 10000)

    ser_tx('0' +   data/10000);

  if(data >= 1000)

    ser_tx( '0' + (data%10000)/ 1000 );

  if(data >= 100)

    ser_tx( '0' + (data%1000)/100 );

  if(data >= 10)

    ser_tx( '0' + (data%100)/10 );

  ser_tx( '0' + data%10 );

}





// this is a blocking receive //

char ser_rcv(void) {

	while (1) {

		if (RCSTA & 2) { // RCSTA bit 1 is overflow error

			// overflow error

			clear_bit(RCSTA,CREN); // CREN is RCStatus bit 4 //

			ser_tmp = RCREG; // flush the rx buffer

			ser_tmp = RCREG;

			ser_tmp = RCREG;

			set_bit(RCSTA,CREN); // CREN = 1;

		}

		else if (RCSTA & 4) { // RCSTA bit 2 is framing error

			// framing error

			ser_tmp = RCREG;

		}

		else if (PIR1 & 32) { // PIR1 bit 5 is RCIF

			ser_tmp = RCREG;

			return ser_tmp;

		}

	}

}



// nonblocking receive returns 0 for any error, including nothing to read

char ser_rcv_nb(void) {



	int problem;

	problem = 1;

	

	while (problem == 1) {

		problem = 0;

		if (RCSTA & 2) { // RCSTA bit 1 is overflow error

			// overflow error

			clear_bit(RCSTA,CREN); // CREN is RCStatus bit 4 //

			ser_tmp = RCREG; // flush the rx buffer

			ser_tmp = RCREG;

			ser_tmp = RCREG;

			set_bit(RCSTA,CREN); // CREN = 1;

			problem = 1;

		}

		else if (RCSTA & 4) { // RCSTA bit 2 is framing error

			// framing error

			ser_tmp = RCREG;

			problem = 1;

		}

		else if (PIR1 & 32) {

		ser_tmp = RCREG;

		return ser_tmp;

		}

	} // end while (problem == 1) //

	return 0; // no byte to receive and no errors; return zero

}



// this next section is for servo control /////////////



char servo_state = 0;

char servo_curr = 0;

char servo_mask = 11111111b; // default that all of portD will be

					// used for servo operations rather 

					// than direct digital output twiddling

char servo_switch = 1;

char servo_pos[8] = {0,0,0,0,0,0,0,0};

char _servo_free = 0;



void servo_init(void) {

    OPTION_REG = 132; // bit 7 = 1 for portB pull-up and bit2 is for prescaler

				// TMR0 @ 1:32, prescaler to timer0 (for servo control)

    TRISD = 0; // port D as outputs	for servo commands!

	// in fact we already do this in init_cerebellum(); we do it again for //

	// redundancy only here //

    set_bit(INTCON, T0IE); //T0IE = 1 ie enable TMR0 overflow bit - T0IE is bit 5

    delay_ms(1);   

}



void do_servo(void) {

	clear_bit(_servo_free,0); // the bit 0 of servo_free = 0;

	if (servo_state == 1) {

		// next intr in 0.6 ms

		TMR0 = 153;

		//TMR0 = 145;

		if ((servo_pos[servo_curr] != 0) && ((servo_mask & servo_switch) != 0))

			PORTD |= servo_switch; // output hi to specific servo pin out

		servo_state = 2;

                set_bit(_servo_free,0); // the bit servo_free = 1;

	}

	else if (servo_state == 2) {

		TMR0 = 255 - servo_pos[servo_curr];

		servo_state = 3;

	}

	else if (servo_state == 3) {

		if ((servo_mask & servo_switch) != 0)

			PORTD &= ~servo_switch; // output lo to this servo bit, but

							// preserve all other digital hi's on port D

		TMR0 = servo_pos[servo_curr];

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美二区在线观看| 欧美性色黄大片| 日韩av成人高清| 亚洲精品国产视频| 亚洲免费观看视频| 国产精品久久影院| 国产精品久久久久影视| 日韩高清不卡在线| 色偷偷久久一区二区三区| 99精品久久久久久| 色菇凉天天综合网| 欧美精品乱码久久久久久| 国产精品免费看片| 一区二区三区欧美在线观看| 亚洲第一会所有码转帖| 蜜桃av噜噜一区二区三区小说| 秋霞电影一区二区| 国产成人av电影在线播放| 成人美女视频在线观看18| 色综合久久久久| 亚洲国产成人一区二区三区| 一区二区三区高清在线| 99久久伊人精品| 中文字幕不卡在线| 国产高清不卡一区二区| 在线视频你懂得一区| 91精品国产91久久久久久最新毛片| 日韩三级免费观看| 中文字幕乱码日本亚洲一区二区| 国产一区二区精品久久91| caoporen国产精品视频| 制服丝袜中文字幕亚洲| 中文字幕va一区二区三区| 国模冰冰炮一区二区| 色综合欧美在线视频区| 日韩美女啊v在线免费观看| 日韩成人午夜电影| 日韩一区二区免费电影| 亚洲福利视频三区| 大尺度一区二区| 国产精品夫妻自拍| 91在线精品一区二区三区| 亚洲欧美日韩国产综合在线| 91免费国产在线| 久久综合九色综合欧美98| 亚洲欧美激情一区二区| 欧美在线观看禁18| 日韩专区一卡二卡| 日本福利一区二区| 石原莉奈在线亚洲二区| 日韩美女主播在线视频一区二区三区 | 日韩电影在线免费观看| 欧美一区二区日韩一区二区| 久久99精品久久只有精品| 99久久精品免费精品国产| 亚洲色欲色欲www| 欧美日韩一区二区在线视频| 国产精品久久久久婷婷| 91成人免费电影| 美女性感视频久久| 国产欧美视频一区二区三区| 免费久久99精品国产| 久久久亚洲精品石原莉奈| 日韩av一二三| 国产精品乱码一区二三区小蝌蚪| 色香蕉久久蜜桃| 精品一二三四区| 亚洲伦在线观看| 2023国产精品视频| 91福利资源站| 黑人巨大精品欧美黑白配亚洲| 亚洲欧洲色图综合| 成人av资源在线观看| 久久久久九九视频| 欧美日韩中文另类| 国产成人综合网站| 日韩精品一区第一页| 国产精品无码永久免费888| 欧美日韩国产一区| 日韩在线a电影| 亚洲男人都懂的| 久久亚洲欧美国产精品乐播 | 国产一区二区不卡老阿姨| 伊人一区二区三区| 国产网红主播福利一区二区| 成人妖精视频yjsp地址| 偷拍亚洲欧洲综合| 欧美一区二区播放| 91精品91久久久中77777| 国产麻豆精品theporn| 亚洲影视资源网| 欧美日韩国产精品自在自线| 成人午夜视频免费看| 久久黄色级2电影| 久久久久久久久久久久电影| 欧美日韩精品一区二区在线播放 | 91精品国产麻豆| 欧美在线一二三四区| 国产不卡视频一区二区三区| 麻豆精品视频在线观看| 香蕉影视欧美成人| 亚洲成人免费在线观看| 亚洲美女免费在线| 亚洲人成网站影音先锋播放| 亚洲国产精华液网站w | 免费的国产精品| 日韩精品一卡二卡三卡四卡无卡| 一区二区三区在线影院| 综合久久久久久久| 亚洲品质自拍视频| 亚洲日本电影在线| 亚洲女人小视频在线观看| 亚洲视频免费在线| 亚洲欧洲综合另类| 亚洲婷婷在线视频| 一区二区欧美国产| 亚洲高清视频在线| 视频精品一区二区| 美女一区二区在线观看| 麻豆成人久久精品二区三区红 | 欧美日本一区二区在线观看| 欧美日韩精品三区| 欧美一级片在线| 久久嫩草精品久久久精品一| 国产色综合久久| 中文字幕视频一区| 亚洲夂夂婷婷色拍ww47| 五月天亚洲婷婷| 狠狠色丁香久久婷婷综| 国产成都精品91一区二区三| 97精品久久久久中文字幕| 在线视频一区二区三区| 3d动漫精品啪啪一区二区竹菊 | 91女人视频在线观看| 欧洲人成人精品| 日韩午夜av电影| 国产午夜一区二区三区| 亚洲三级理论片| 日韩成人一区二区| 丰满少妇久久久久久久 | 国产精品99久久久久久久女警| 亚洲尤物在线视频观看| 日韩高清在线电影| 国产精品自在欧美一区| 91美女在线视频| 在线播放一区二区三区| 精品成人佐山爱一区二区| 51精品久久久久久久蜜臀| 国产日韩三级在线| 亚洲女与黑人做爰| 日韩1区2区3区| 福利视频网站一区二区三区| 精品视频1区2区3区| www国产精品av| 一区二区成人在线视频| 国内精品写真在线观看| 91丝袜美女网| 欧美大白屁股肥臀xxxxxx| 3751色影院一区二区三区| 欧美激情资源网| 婷婷成人综合网| va亚洲va日韩不卡在线观看| 欧美人体做爰大胆视频| 国产精品色一区二区三区| 午夜不卡av免费| 99免费精品视频| 精品精品国产高清a毛片牛牛| 亚洲精品美国一| 成人午夜私人影院| 欧美xxx久久| 性欧美疯狂xxxxbbbb| 97国产一区二区| 国产校园另类小说区| 全部av―极品视觉盛宴亚洲| 欧洲av在线精品| 成人免费一区二区三区在线观看| 久久 天天综合| 欧美日韩成人激情| 一区二区三区四区国产精品| 国产91对白在线观看九色| 欧美变态tickle挠乳网站| 天堂久久久久va久久久久| 色偷偷久久一区二区三区| 中文字幕制服丝袜成人av| 国产精品一区二区免费不卡| 日韩一级片网站| 日韩精品一二三四| 欧美高清一级片在线| 亚洲一区av在线| 在线观看视频一区二区欧美日韩| 亚洲欧洲国产专区| 不卡视频免费播放| 中文字幕av免费专区久久| 国产suv精品一区二区三区| 久久综合九色欧美综合狠狠| 免费高清在线一区| 欧美成人a在线| 狠狠色丁香久久婷婷综合_中| 精品女同一区二区| 韩国视频一区二区|