久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1610|回復(fù): 3
打印 上一主題 下一主題
收起左側(cè)

這個怎么外接12864啊

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:386561 發(fā)表于 2018-8-24 14:32 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include <reg52.h>
#include <stdio.h>
#include <math.h>
#include <intrins.h>

#define KeyPort P0
#define uchar unsigned char
#define uint unsigned int
#define DataPort P0


  sbit ADDO = P1^6;
  sbit ADSK = P1^7;

unsigned int num;
unsigned int dnf;
float i;
unsigned int priceV;
//////////////////////////


/*-----------------------------------------------
  LCD12864引腳接口
------------------------------------------------*/
sbit RS = P2^4;
sbit RW = P2^5;
sbit E  = P2^6;
sbit RES = P2^3;
sbit PSB = P2^1;
sbit PAUSE = P3^0;


unsigned char temp[16];
unsigned char lol[16];

void DelayUs2x(unsigned char t)
{   
while(--t);
}
void DelayMs(unsigned char t)
{

while(t--)
{
     //大致延時1mS
     DelayUs2x(245);
         DelayUs2x(245);
}
}
/*------------------------------------------------
                    檢測忙位
------------------------------------------------*/
void Check_Busy()
{  
    RS=0;
    RW=1;
    E=1;
    DataPort=0xff;
    while((DataPort&0x80)==0x80);//忙則等待
    E=0;
}
/*------------------------------------------------
                   寫命令
------------------------------------------------*/
void Write_Cmd(unsigned char Cmd)
{
        Check_Busy();
        RS=0;
        RW=0;
        E=1;
        DataPort=Cmd;
        DelayUs2x(5);
        E=0;
        DelayUs2x(5);
}
/*------------------------------------------------
                    寫數(shù)據(jù)
------------------------------------------------*/
void Write_Data(unsigned char Data)
{
        Check_Busy();
        RS=1;
        RW=0;
        E=1;
        DataPort=Data;
        DelayUs2x(5);
        E=0;
        DelayUs2x(5);
}
/*------------------------------------------------
                   液晶屏初始化
------------------------------------------------*/
void Init_ST7920()
{  
   DelayMs(40);           //大于40MS的延時程序
   PSB=1;                 //設(shè)置為8BIT并口工作模式
   DelayMs(1);            //延時
   RES=0;                 //復(fù)位
   DelayMs(1);            //延時
   RES=1;                 //復(fù)位置高
   DelayMs(10);
   Write_Cmd(0x30);       //選擇基本指令集
   DelayUs2x(50);         //延時大于100us
   Write_Cmd(0x30);       //選擇8bit數(shù)據(jù)流
   DelayUs2x(20);         //延時大于37us
   Write_Cmd(0x0c);       //開顯示(無游標(biāo)、不反白)
   DelayUs2x(50);         //延時大于100us
   Write_Cmd(0x01);       //清除顯示,并且設(shè)定地址指針為00H
   DelayMs(15);           //延時大于10ms
   Write_Cmd(0x06);       //指定在資料的讀取及寫入時,設(shè)定游標(biāo)的移動方向及指定顯示的移位,光標(biāo)從右向左加1位移動
   DelayUs2x(50);         //延時大于100us
}


/*------------------------------------------------
                   顯示字符串
x:橫坐標(biāo)值,范圍0~8
y:縱坐標(biāo)值,范圍1~4
------------------------------------------------*/
void LCD_PutString(unsigned char x,unsigned char y,unsigned char *s)
{
switch(y)
     {
          case 1: Write_Cmd(0x80+x);break;
          case 2: Write_Cmd(0x90+x);break;
          case 3: Write_Cmd(0x88+x);break;
          case 4: Write_Cmd(0x98+x);break;
      default:break;
         }
while(*s>0)
   {
      Write_Data(*s);
      s++;
      DelayUs2x(50);
   }
}
/*------------------------------------------------
                      清屏
------------------------------------------------*/
void ClrScreen()
{
   Write_Cmd(0x01);
   DelayMs(15);
}
/*------------------------------------------------
                   延時函數(shù)
------------------------------------------------*/
void delay(uchar z)
{
        uchar x;
        for(;z>0;z--)
                for(x=22;x>0;x--);
}
                  
unsigned long ReadCount(void)
{
unsigned long Count; unsigned char i;
ADSK=0;        //使能AD(PD_SCK 置低)
Count=0;
while(ADDO);        //AD轉(zhuǎn)換未結(jié)束則等待,否則開始讀取
for (i=0;i<24;i++)
{
ADSK=1;        //PD_SCK 置 高 ( 發(fā) 送 脈 沖 )
Count=Count<<1; //下降沿來時變量Count左移一位,右側(cè)補零
ADSK=0;        //PD_SCK 置低
if(ADDO) Count++;
}
ADSK=1;
Count=Count^0x800000;//第25個脈沖下降沿來時,轉(zhuǎn)換數(shù)據(jù)
ADSK=0;
return(Count);
}
///////////////////////////////////////////////////////////////// //////////////////////
/*------------------------------------------------
按鍵掃描函數(shù),返回掃描鍵值
------------------------------------------------*/
unsigned char KeyScan(void)  //鍵盤掃描函數(shù),使用行列反轉(zhuǎn)掃描法
{
unsigned char cord_h,cord_l;//行列值中間變量
KeyPort=0x0f;            //行線輸出全為0
cord_h=KeyPort&0x0f;     //讀入列線值
if(cord_h!=0x0f)    //先檢測有無按鍵按下
{
  DelayMs(10);        //去抖
  if((KeyPort&0x0f)!=0x0f)
  {
    cord_h=KeyPort&0x0f;  //讀入列線值
    KeyPort=cord_h|0xf0;  //輸出當(dāng)前列線值
    cord_l=KeyPort&0xf0;  //讀入行線值

    while((KeyPort&0xf0)!=0xf0);//等待松開并輸出

    return(cord_h+cord_l);//鍵盤最后組合碼值
   }
  }return(0xff);     //返回該值
}
/*------------------------------------------------
          按鍵值處理函數(shù),返回掃鍵值
           可以根據(jù)需要改變返回值

                          | 1 | 2 | 3 | + |  
                          | 4 | 5 | 6 | - |  
                          | 7 | 8 | 9 | * |  
                          | 0 | . | = | / |
------------------------------------------------*/
unsigned char KeyPro(void)
{
switch(KeyScan())
{

        case 0x77:return  1  ;break;//1
        case 0x7b:return  2  ;break;//2
        case 0x7d:return  3  ;break;//3                 
        case 0xb7:return  4  ;break;//4
        case 0xbb:return  5  ;break;//5
    case 0xbd:return  6  ;break;//6
    case 0xd7:return  7  ;break;//7
        case 0xdb:return  8  ;break;//8
    case 0xdd:return  9  ;break;//9         
    case 0xe7:return 10 ;break;//*
    case 0x7e:return 11;break;//A  設(shè)置單價                                    
    case 0xbe:return 12 ;break;//B         去皮                             
    case 0xde:return 13 ;break;//C  附加功能                                                    
    case 0xee:return 14 ;break;//D    重置                                   
        case 0xed:return 15 ;break;//#
    case 0xeb:return 16  ;break;//0                                                                    

  default:return 0;break;

}
}


/*------------------------------------------------
              主程序
------------------------------------------------*/
main()
{

int priceV;

char v=0;
unsigned long   weight   ;
unsigned long   heavy  ;
float                     heavy1 ;
float           poi;
int d1,d2;
        ClrScreen();
    Init_ST7920();   //初始化
heavy= ReadCount();        DelayMs(100);
heavy= ReadCount();        DelayMs(100);
heavy= ReadCount();        DelayMs(100);
while (1)
{

for( v=0;v<6;v++)
  {        weight += ReadCount();     }         
  weight =weight/7;
heavy1= weight-heavy  ;
heavy1= (float)heavy1/1834.5;
        DelayMs(150);        DelayMs(150);
if(heavy1>10000)heavy1=0;
d1 = weight / 1000;        d2 = weight % 1000;
num=KeyPro();       
poi=priceV*heavy1*10;


        switch(num)

        {
        case 1:        priceV*=10; priceV+=1;            break;                // 1
        case 2:        priceV*=10; priceV+=2;                break;                 // 2
        case 3:        priceV*=10; priceV+=3;                break;                 // 3
        case 4:        priceV*=10; priceV+=4;                break;                 // 4
        case 5:        priceV*=10; priceV+=5;                break;                 // 5
        case 6:        priceV*=10; priceV+=6;                break;                 // 6
        case 7:        priceV*=10; priceV+=7;                break;                 // 7
        case 8: priceV*=10; priceV+=8;                break;                 // 8
        case 9: priceV*=10; priceV+=9;                break;                 // 9
        case 16: priceV*=10;                         break;
        case 15: priceV=0;                        break;                  // 0
        case 11: heavy= ReadCount();        break;
        case 12: i+=poi;                    break;
    case 13: i=0;                       break;
       
       
       
       
        }


                sprintf(temp,"重量:%5.2f g       " ,heavy1 );
                LCD_PutString(0,1, temp);
                sprintf(lol,"單價:%4d 元/g   ",priceV);
                LCD_PutString(0,2, lol);
                sprintf(lol,"總價:%4.1f 元/g  ",poi/10);
                LCD_PutString(0,3, lol);
//                sprintf(lol,"共計:%4.1f 元/g  ",i/10);
//            LCD_PutString(0,4, lol);
                sprintf(temp," %4d%-d          ",d1,d2);
            LCD_PutString(0,4, temp);
                DelayMs(200);       
       
       

if(heavy1>503)
   {
   ClrScreen();
   sprintf(lol,"警告警告警告警告");
            LCD_PutString(0,1, lol);
                 sprintf(lol,"警告警告警告警告");
            LCD_PutString(0,2, lol);
                 sprintf(lol,"警告警告警告警告");
            LCD_PutString(0,3, lol);
                 sprintf(lol,"警告警告警告警告");
            LCD_PutString(0,4, lol);
                DelayMs(200);
   }

}
}




現(xiàn)在不會外接12864

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:387733 發(fā)表于 2018-8-24 17:29 | 只看該作者
/*-----------------------------------------------
  LCD12864引腳接口
------------------------------------------------*/
sbit RS = P2^4;
sbit RW = P2^5;
sbit E  = P2^6;
sbit RES = P2^3;
sbit PSB = P2^1;
sbit PAUSE = P3^0;
就按這個接呀

評分

參與人數(shù) 1黑幣 +20 收起 理由
admin + 20 回帖助人的獎勵!

查看全部評分

回復(fù)

使用道具 舉報

板凳
ID:164602 發(fā)表于 2018-8-25 08:08 | 只看該作者
程序有問題吧?!
你的P0被改名兩次:
#define KeyPort P0
#define DataPort P0
回復(fù)

使用道具 舉報

地板
ID:98526 發(fā)表于 2018-8-25 09:18 | 只看該作者
HC6800-ES-V2.0 發(fā)表于 2018-8-25 08:08
程序有問題吧?!
你的P0被改名兩次:
#define KeyPort P0

按鍵跟12864的數(shù)據(jù)口復(fù)用了吧
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 精品中文字幕一区二区三区 | 国产精品一区二区三区久久 | 国产高清视频 | 欧美另类视频 | 亚洲情综合五月天 | 国产在线www| 情侣av| 看a网站 | 午夜99 | 亚洲欧美在线免费观看 | 亚洲精选一区 | 国产精品亚洲一区二区三区在线 | 在线观看黄免费 | 91久久久精品国产一区二区蜜臀 | 日韩三极 | 围产精品久久久久久久 | 中文av电影 | 天天精品在线 | 亚洲精品视频一区 | 亚洲午夜精品在线观看 | 日韩福利| 亚洲欧洲成人在线 | 亚洲天天干| 日本精品视频在线 | 中文字幕乱码一区二区三区 | 国产精品免费一区二区三区四区 | 999热在线视频 | 看黄在线 | 日韩综合一区 | 亚洲国产视频一区二区 | 蜜臀网| 久久久久久国产精品免费免费 | 羞羞视频在线观看免费观看 | 成人在线观看免费爱爱 | 欧美性video| 九九亚洲 | 成人精品免费视频 | 国产高清在线 | 天天人人精品 | 亚洲综合无码一区二区 | 日韩欧美中文在线 |