CH02_IF语句示例程序

package cn.pzhu.java.ch02;

public class IFDemo {
	static boolean test(int i){
		System.out.println("Call test(int i)");
		return i>10;
	}
	static boolean t1(int i){
		System.out.println("Call t1(int i)");
		//return i<10;
		return i>10;
	}
	static boolean t2(int i){
		System.out.println("Call t2(int i)");
		return i==5;
	}
	
	public static void main(String[] args) {
		
		/**
		  boolean f=false;
		 int i=100;
		//if(f=false){   //特例
		if(f==false){
			System.out.println("OK");
		}else{
			System.out.println("Other");
		}
		*/
		
		 //方法作为条件
		 /*if(test(11)){  
			System.out.println("OK");
		}else{
			System.out.println("Other");
		}*/
		
		//短路测试
		int i=100;
		int j=5;
		//if(t1(i)&&t2(j)){  
		//if(t1(i)&t2(j)){
		//if(t1(i)||t2(j)){
		if(t1(i)|t2(j)){
			System.out.println("OK");
		}else{
			System.out.println("Other");
		}
	}
	

}

uint32 bluetooth_ch9141_read_buff (uint8 *buff, uint32 len) { uint32 data_len = len; fifo_read_buffer(&bluetooth_ch9141_fifo, buff, &data_len, FIFO_READ_AND_CLEAN); return data_len; }uint32 bluetooth_ch9141_send_buff (uint8 *buff, uint32 len) { uint16 time_count = 0; while(len > 30) { time_count = 0; while(BLUETOOTH_CH9141_RTS_PIN && time_count++ < BLUETOOTH_CH9141_TIMEOUT_COUNT) // 如果RTS为低电平,则继续发送数据 delay_ms(1); if(time_count >= BLUETOOTH_CH9141_TIMEOUT_COUNT) return len; // 模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 uart_putbuff(BLUETOOTH_CH9141_INDEX, buff, 30); buff += 30; // 地址偏移 len -= 30; // 数量 } time_count = 0; while(BLUETOOTH_CH9141_RTS_PIN && time_count++ < BLUETOOTH_CH9141_TIMEOUT_COUNT) // 如果RTS为低电平,则继续发送数据 delay_ms(1); if(time_count >= BLUETOOTH_CH9141_TIMEOUT_COUNT) return len; // 模块忙,如果允许当前程序使用while等待 则可以使用后面注释的while等待语句替换本if语句 uart_putbuff(BLUETOOTH_CH9141_INDEX, buff, (uint16)len); // 发送最后的数据 return 0; }uint8 bluetooth_ch9141_init (void) { wireless_type = WIRELESS_CH9141; // 本函数使用的波特率为115200 为蓝牙转串口模块的默认波特率 如需其他波特率请使用上位机修改模块参数 fifo_init(&bluetooth_ch9141_fifo, bluetooth_ch9141_buffer, BLUETOOTH_CH9141_BUFFER_SIZE); uart_init(BLUETOOTH_CH9141_INDEX, BLUETOOTH_CH9141_TX_PIN, BLUETOOTH_CH9141_RX_PIN, BLUETOOTH_CH9141_BUAD_RATE, BLUETOOTH_CH9141_TIMER); return 0; } void bluetooth_ch9141_uart_callback (void) { // 读取无线串口的数据 并且置位接收标志 bluetooth_ch9141_data = BLUETOOTH_CH9141_DATA_BUF; fifo_write_buffer(&bluetooth_ch9141_fifo, &bluetooth_ch9141_data, 1); // 存入 FIFO } static fifo_struct bluetooth_ch9141_fifo; static uint8 bluetooth_ch9141_buffer[BLUETOOTH_CH9141_BUFFER_SIZE]; // 数据存放数组 static uint8 bluetooth_ch9141_data;以以上代码为示例编写一个适合于HC-05的蓝牙代码
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值