Esempio n. 1
0
/*************************************************************************
                                主函数
**************************************************************************/
void main()
{

    uchar key;
    Init_Com();//串口初始化
    count=0;
    P0=0xbf;
    fmq=0;
    while(1)
    {
        P1=0x0f;
        if(P1!=0x0f)
        {
            delay(400);

            key=getkey();
            Getch(key);
            delay(400);

        }

        xianshi();

    }
}
Esempio n. 2
0
/*************************************************************************
                                判断键值	
**************************************************************************/
void Getch (uchar i)
{

switch (i) //判断键值(那一个键按下)
{
case 0xe7: if (count<6) { mbuf[count]=1; xianshi();count++;SBUF=65;while(!TI);TI=0;}break;
case 0xd7: if (count<6) { mbuf[count]=2; xianshi();count++;SBUF=66;while(!TI);TI=0;}break;
case 0xb7: if (count<6) { mbuf[count]=3; xianshi();count++;SBUF=67;while(!TI);TI=0;}break;
case 0x77: if (count<6) { mbuf[count]=4; xianshi();count++;SBUF=68;while(!TI);TI=0;}break;
case 0xeb: if (count<6) { mbuf[count]=5; xianshi();count++;SBUF=69;while(!TI);TI=0;}break;
case 0xdb: if (count<6) { mbuf[count]=6; xianshi();count++;SBUF=70;while(!TI);TI=0;}break;
case 0xbb: if (count<6) { mbuf[count]=7; xianshi();count++;SBUF=71;while(!TI);TI=0;}break;
case 0x7b: if (count<6) { mbuf[count]=8; xianshi();count++;SBUF=72;while(!TI);TI=0;}break;
case 0xed: if (count<6) { mbuf[count]=9; xianshi();count++;SBUF=73;while(!TI);TI=0;}break;
case 0xdd: if (count<6) { mbuf[count]=10;xianshi();count++;SBUF=74;while(!TI);TI=0;}break;
case 0xbd: if (count==6) {pwflag = pwcmp();if(pwflag==1){fmq=1;}}break; 
case 0x7d: if (count<=6) {count=0;QX=1;}break;

} } 
Esempio n. 3
0
/////////按设置格式显示///
//磅,正计数 5      //磅,到计数 6//千克,正计数 9 //千克,到计数 10
void  disp_all(void)//bit4千克  bit3磅    bit2倒计   bit1正计
{
    if(unit<0x07)      dig_16_10((21-weight)*10,count);  //磅
    else                                                //千克
    {
        dig_16_10(weighlist[weight],count);
        if(weight==20) show_led_char[1]|=0x80;
    }
    show_led_char[5]=unit;
    xianshi(show_led_char);
}
Esempio n. 4
0
/*************************************************************************
                                主函数	
**************************************************************************/
 void main()
{ 

uchar key;
Init_Com();//串口初始化
count=0;
P0=0xbf;
fmq=0;
while(1)
	{
P1=0x0f;
if(P1!=0x0f)  
 {
  delay(400);
   
  key=getkey(); 
  Getch(key);
  delay(400); 
  
 } 
  disp();
  if(cesi==0){{pwflag = pwcmp();if(pwflag==1){fmq=1;}}}
  xianshi();
 if(QX==1)
{
mbuf[count]=0; count++;
mbuf[count]=0; count++;
mbuf[count]=0; count++;
mbuf[count]=0; count++;
mbuf[count]=0; count++;
mbuf[count]=0; 
xianshi();
QX=0;
count=0;

}  
}
}		
Esempio n. 5
0
int main(int argc, const char *argv[])
{
	ret = sqlite3_open("./test.db", &db);
	if (ret != SQLITE_OK) {
		fputs(sqlite3_errmsg(db), stderr);
		fputs("\n", stderr);
		exit(1);
	}
	//sql =
	 //   sqlite3_mprintf
	//    ("create table student(id integer primary key,name text,gender text,age integer);");
	//ret = sqlite3_exec(db, sql, 0, 0, &err);
	while (1) {
		printf("1.Display all records\n");
		printf("2.Insert Record\n");
		printf("3.Delete Record\n");
		printf("4.Exit\n");
		printf("Please Select[1-4]:");
		int i;
		scanf("%d", &i);
		switch (i) {
		case 1:
			xianshi();
            empty_cache();
			break;
		case 2:
			charu();
            empty_cache();
			break;
		case 3:
			shanchu();
         	empty_cache();
			break;
		case 4:
			exit(0);
			break;
		default:
            empty_cache();
			break;
		}
	}
	if (ret != SQLITE_OK) {
		fputs(err, stderr);
		fputs("\n", stderr);
		sqlite3_close(db);
		exit(1);
	}
	sqlite3_close(db);
	return 0;
}
Esempio n. 6
0
/////////////////////main start////////////////////////
int main(void)
{
    sysclk_ini();
    sysio_ini();
// Uart_Init();
    Light(led_channel);
    tmi1_ini();
// xianshi(show_led_char);
    if(unit&0x02) count=con_count;
    else          count=0;
    __enable_interrupt();
    while (1)
    {
        if(work_state>0x10)  sys1ms=0;
        if(sys1ms)
        {
            --sys1ms;
            Read165(sensor_chk);
            if(led_channel==6) next_channel=0;
            else               next_channel=led_channel+1;
            Light(next_channel);
            for(unsigned char j=0; j<4; j++)
            {
                if((sensor_chk[j]&(2<<led_channel))==0)
                {
                    temp_have_led[temp_led_n]=7-led_channel+7*j;
                    if(++temp_led_n>7)  temp_led_n=7 ;
                }
            }
            ++led_channel;
            if(led_channel>6)//||(temp_led_n))
            {
//        if(++comrecive1.comtime>20)
//        {
//          comrecive1.comtime=0;
//          comrecive1.compra=0;
//        }

                if(temp_have_led[0]!=sensor_bk)
                {
                    if(temp_led_n==1)  temp_led_ok=temp_have_led[0];
                    else               temp_led_ok=0;
                    norun=0;
                }
                else
                {
                    if(++norun>42857)  //10分钟没动作,关显示
                    {
                        work_state=5;
                        led_off();
                    }
                    temp_led_ok=0;
                }
                sensor_bk=temp_have_led[0];
                led_channel=0;
                if(work_state==2)//检测速度
                {
                    unsigned int temp_jul;
                    if(temp_led_ok)
                    {
                        move_stop_time=0;
                        if(rev_nn<10) ++rev_nn;
                        else       rev_weight=0;
                        now_high=temp_led_ok;//weizhilist[temp_led_ok-1];
                        if((now_high>pro_high)&&(f_sign==0))
                        {
                            f_sign=1;
                            julihigh=temp_led_ok;
                            pro_time=systime;
                        }
                        else  if((now_high<pro_high)&&f_sign)
                        {

                            if(now_time>pro_time) temp_jul=now_time-pro_time;
                            else                  temp_jul=65536-pro_time+now_time;
                            speed= (Highlist(pro_high)-Highlist(julihigh))*10/temp_jul;
                            speed=speed%40;
                            f_sign =0;

                            if(unit&0x01)  ++count;
                            else
                            {
                                if(count>1) --count;
                                else        count=con_count;
                            }
                        }
                        now_time=systime;
                        if(pro_high==weight)  treadmil_set=1;//上次回归到了重量设置起始处,判断换稍子用
                        else                  treadmil_set=0;
                        pro_high=now_high;

                        disp_all();

                        //   uart_event=1;
                        //uart_send_time=500;//uart_send_str (uart_send_buf);
                        nosockt=0;
                    }
                    else
                    {
                        if(temp_led_n==0)
                        {
                            if((rev_weight)&&(now_high==weight))//2S z之内没有插销,且插销消失前位于移动的最低端
                            {
                                if(++rev_weight==0)   rev_weight=101;///=2;
                            }
                            //  else             rev_weight=0;
                            move_stop_time=0;
                            rev_nn=0;
                            if(++nosockt>40000) work_state=0;
                        }
                        else if(temp_led_n==1)
                        {
                            nosockt=0;
                            ++move_stop_time;
                            if(move_stop_time>698)//在上次重量位置处保持2秒---698---1.1秒--400
                            {
                                if( weight==temp_have_led[0]) rev_weight=1;// 回到移动的最低端
                                else
                                {
                                    if((rev_weight>100) &&(rev_nn<2)) //没有插销的时间超过0.3秒,且是第一次出现插销
                                    {
                                        f_sign=0;
                                        weight=temp_have_led[0]%25;
                                        speed = 0;

                                        disp_all();

                                    }
                                    rev_weight=0;
                                }
                            }
                            else if(move_stop_time>9)//30ms 去抖
                            {
                                unsigned char tempf=0;
                                if(temp_have_led[0]<weight)  tempf=1; //如果出现更重的重量,表明刚换了插销
                                else
                                {
                                    if(treadmil_set&&((temp_have_led[0]-weight)>1)) tempf=1;
                                    //如果上次出现在设置的重量处,这次出现在间隔的地方也表明刚换了插销
                                }
                                if(tempf)
                                {
                                    weight=temp_have_led[0]%25;
                                    speed = 0;

                                    disp_all();

                                    rev_weight=0;
                                    move_stop_time=0;
                                }
                            }
                        }
                    }
                }
                else  if(work_state==0)  //上电自检传感器
                {
                    if((systime%50)==0)
                    {
                        //unsigned char i;
                        if(temp_led_n>1)//出错情况
                        {
                            errlednum=temp_led_n;
                            dig_16_10(temp_have_led[0],temp_have_led[1]);
                            show_led_char[0]=0x79;
                            xianshi(show_led_char);
                        }
                        else if(temp_led_n==0)//无插销情况
                        {
                            errlednum=100;
                            show_led_char[0]=0x71;
                            show_led_char[1]=0x40;
                            show_led_char[2]=0x40;
                            show_led_char[3]=0x40;
                            show_led_char[4]=0x40;
                            show_led_char[5]=0x40;
                            show_led_char[5]=unit;
                            xianshi(show_led_char);
                        }
                        else
                        {
                            errlednum=0;
                            // dig_16_10(0,0);
                            // xianshi(show_led_char);
                        }
                    }
                    if((++testtime>200)&&(errlednum==0))//检测正常
                    {
                        testtime=0;
                        weight=temp_have_led[0]%20;//weizhilist[temp_have_led[0]-1];
                        now_high=weight;
                        work_state=2;

                        disp_all();

                    }
                }

                temp_led_n=0;
            }

        }

        if((systime%10)==0)
        {
            key_buf = read( );
            if(key_buf!=0xff)//有按键
            {
                if(key_buf!=key_pro)//新按键
                {
                    if(work_state==5)//结束显示休眠
                    {
                        work_state=0;
                        led_on();
                        norun=0;
                    }
                    else
                    {
                        if(work_state>0x10) //设置状态
                        {
                            if(key_buf==KEY_CLR_D) //确认键
                            {
                                if(work_state==0x11)
                                {
                                    unit=set_vol;
                                    //show_led_char[5]=unit;
                                    flash_flag=2;
                                    work_state=0x12;
                                }
                                else if(work_state==0x12)
                                {
                                    unit=set_vol;
                                    // show_led_char[5]=unit;
                                    if(unit&0x02)//倒计模式,设置倒计数值
                                    {
                                        set_vol=con_count;
                                        flash_flag=3;
                                        work_state=0x13;
                                    }
                                    else//正计数,结束设置
                                    {
                                        flash_flag=0;
                                        work_state=0;
                                        disp_all();
                                    }
                                }
                                else if(work_state==0x13)//结束设置
                                {
                                    con_count=set_vol;
                                    flash_flag=0;
                                    work_state=0;
                                    disp_all();
                                }

                            }
                            else if(key_buf==KEY_SET) //设置键
                            {
                                if(work_state==0x11)
                                {
                                    if(set_vol&0x04)  set_vol=(set_vol&0x03)|0x08;//8  千克
                                    else              set_vol=(set_vol&0x03)|0x04; //4 磅
                                    unit=set_vol;
                                }
                                else if(work_state==0x12)
                                {
                                    if(set_vol&0x01)  set_vol=(set_vol&0x0c)|0x02;//2    倒计模式
                                    else              set_vol=(set_vol&0x0c)|0x01; //1   正计模式
                                    unit=set_vol;
                                }
                                else if(work_state==0x13)//设置设置计数
                                {
                                    if(set_vol>0) --set_vol;

                                }
                            }
                        }
                        else  //清楚计数
                        {
                            if(key_buf==KEY_CLR_D)//清楚键
                            {
                                if(unit&0x01)  count=0;
                                else           count=con_count;
                                disp_all();
                            }
                        }
                    }

                    key_time=0;
                }
                else  //长按键  判断
                {
                    ++key_time;
                    if(key_buf==KEY_SET)//设置键
                    {
                        if((key_time>200)&&(work_state<0x10))
                        {
                            work_state=0x11;
                            set_vol=unit;
                            flash_flag=1;
                            flash_time=0;
                        }
                        else if((key_time>100)&&(work_state==0x13))
                        {
                            if(set_vol>10) set_vol=set_vol-10;
                            else           set_vol=95;
                            key_time=0;
                        }
                    }
                }
            }
            key_pro = key_buf;
            if(flash_flag)
            {
                ++flash_time;
                show_led_char[0]=0;
                show_led_char[1]=0;
                show_led_char[2]=0;
                if(flash_time==1)
                {
                    if(work_state==0x13)
                    {
                        show_led_char[5]=unit;
                        show_led_char[4]=0;
                        show_led_char[3]=0;
                    }
                    else
                    {
                        if(work_state==0x11)  show_led_char[5]=unit&0x03;
                        else                  show_led_char[5]=unit&0x0c;
                    }
                    xianshi(show_led_char);
                }
                else if(flash_time==50)
                {
                    if(work_state==0x13)
                    {
                        show_led_char[4]=lednest[set_vol%10];
                        show_led_char[3]=lednest[set_vol/10];
                    }
                    else
                    {
                        show_led_char[4]=lednest[count%10];
                        show_led_char[3]=lednest[count/10];
                    }
                    show_led_char[5]=unit;
                    xianshi(show_led_char);

                }
                if(flash_time>100)  flash_time=0;

            }
        }
    }

}