找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

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

STC15W205S單片機(jī)如何讀取IO值?

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:457181 發(fā)表于 2018-12-28 15:37 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
我是一名新手,從沒(méi)接觸過(guò)單片機(jī)。第一次用STC15W205S,我想知道是否能讀取IO的值是0或1?
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:457374 發(fā)表于 2018-12-28 16:09 | 只看該作者
可以的,需要配置IO口,其它和51單片機(jī)一樣。
可以參考下。
#include "reg51.h"

sfr P0M1 = 0x93;
sfr P0M0 = 0x94;
sfr P1M1 = 0x91;
sfr P1M0 = 0x92;
sfr P2M1 = 0x95;
sfr P2M0 = 0x96;
sfr P3M1 = 0xb1;
sfr P3M0 = 0xb2;
sfr P4M1 = 0xb3;
sfr P4M0 = 0xb4;
sfr P5M1 = 0xC9;
sfr P5M0 = 0xCA;
sfr P6M1 = 0xCB;
sfr P6M0 = 0xCC;
sfr P7M1 = 0xE1;
sfr P7M0 = 0xE2;

sbit P00 = P0^0;
sbit P01 = P0^1;
sbit P02 = P0^2;
sbit P03 = P0^3;
sbit P04 = P0^4;
sbit P05 = P0^5;
sbit P06 = P0^6;
sbit P07 = P0^7;
sbit P10 = P1^0;
sbit P11 = P1^1;
sbit P12 = P1^2;
sbit P13 = P1^3;
sbit P14 = P1^4;
sbit P15 = P1^5;
sbit P16 = P1^6;
sbit P17 = P1^7;
sbit P20 = P2^0;
sbit P21 = P2^1;
sbit P22 = P2^2;
sbit P23 = P2^3;
sbit P24 = P2^4;
sbit P25 = P2^5;
sbit P26 = P2^6;
sbit P27 = P2^7;
sbit P30 = P3^0;
sbit P31 = P3^1;
sbit P32 = P3^2;
sbit P33 = P3^3;
sbit P34 = P3^4;
sbit P35 = P3^5;
sbit P36 = P3^6;
sbit P37 = P3^7;

sfr P4   = 0xC0;
sbit P40 = P4^0;
sbit P41 = P4^1;
sbit P42 = P4^2;
sbit P43 = P4^3;
sbit P44 = P4^4;
sbit P45 = P4^5;
sbit P46 = P4^6;
sbit P47 = P4^7;

sfr P5   = 0xC8;
sbit P50 = P5^0;
sbit P51 = P5^1;
sbit P52 = P5^2;
sbit P53 = P5^3;
sbit P54 = P5^4;
sbit P55 = P5^5;
sbit P56 = P5^6;
sbit P57 = P5^7;

sfr P6   = 0xE8;
sbit P60 = P6^0;
sbit P61 = P6^1;
sbit P62 = P6^2;
sbit P63 = P6^3;
sbit P64 = P6^4;
sbit P65 = P6^5;
sbit P66 = P6^6;
sbit P67 = P6^7;

sfr P7   = 0xF8;
sbit P70 = P7^0;
sbit P71 = P7^1;
sbit P72 = P7^2;
sbit P73 = P7^3;
sbit P74 = P7^4;
sbit P75 = P7^5;
sbit P76 = P7^6;
sbit P77 = P7^7;

void delay()
{
    int i, j;

    for (i=0; i<1000; i++)
    for (j=0; j<500; j++);
}


void main()
{
    P0M0 = 0x00;
    P0M1 = 0x00;
    P1M0 = 0x00;
    P1M1 = 0x00;
    P2M0 = 0x00;
    P2M1 = 0x00;
    P3M0 = 0x00;
    P3M1 = 0x00;
    P4M0 = 0x00;
    P4M1 = 0x00;
    P5M0 = 0x00;
    P5M1 = 0x00;
    P6M0 = 0x00;
    P6M1 = 0x00;
    P7M0 = 0x00;
    P7M1 = 0x00;

    P10 = 0;
    delay();
    P10 = 1;
    P11 = 0;
    delay();
    P11 = 1;
    P12 = 0;
    delay();
    P12 = 1;
    P13 = 0;
    delay();
    P13 = 1;
    P14 = 0;
    delay();
    P14 = 1;
    P15 = 0;
    delay();
    P15 = 1;
    P16 = 0;
    delay();
    P16 = 1;
    P17 = 0;
    delay();
    P17 = 1;

//    P30 = 0;          //P3.0/P3.1為仿真口和USB下載口時(shí)不可演示
//    delay();
//    P30 = 1;
//    P31 = 0;
//    delay();
//    P31 = 1;
    P32 = 0;
    delay();
    P32 = 1;
    P33 = 0;
    delay();
    P33 = 1;
    P34 = 0;
    delay();
    P34 = 1;
    P35 = 0;
    delay();
    P35 = 1;
    P36 = 0;
    delay();
    P36 = 1;
    P37 = 0;
    delay();
    P37 = 1;

    P20 = 0;
    delay();
    P20 = 1;
    P21 = 0;
    delay();
    P21 = 1;
    P22 = 0;
    delay();
    P22 = 1;
    P23 = 0;
    delay();
    P23 = 1;
    P24 = 0;
    delay();
    P24 = 1;
    P25 = 0;
    delay();
    P25 = 1;
    P26 = 0;
    delay();
    P26 = 1;
    P27 = 0;
    delay();
    P27 = 1;

    P00 = 0;
    delay();
    P00 = 1;
    P01 = 0;
    delay();
    P01 = 1;
    P02 = 0;
    delay();
    P02 = 1;
    P03 = 0;
    delay();
    P03 = 1;
    P04 = 0;
    delay();
    P04 = 1;
    P05 = 0;
    delay();
    P05 = 1;
    P06 = 0;
    delay();
    P06 = 1;
    P07 = 0;
    delay();
    P07 = 1;

    P40 = 0;
    delay();
    P40 = 1;
    P41 = 0;
    delay();
    P41 = 1;
    P42 = 0;
    delay();
    P42 = 1;
    P43 = 0;
    delay();
    P43 = 1;
    P44 = 0;
    delay();
    P44 = 1;
    P45 = 0;
    delay();
    P45 = 1;
    P46 = 0;
    delay();
    P46 = 1;
    P47 = 0;
    delay();
    P47 = 1;

    P50 = 0;
    delay();
    P50 = 1;
    P51 = 0;
    delay();
    P51 = 1;
    P52 = 0;
    delay();
    P52 = 1;
    P53 = 0;
    delay();
    P53 = 1;
    P54 = 0;
    delay();
    P54 = 1;
    P55 = 0;
    delay();
    P55 = 1;
    P56 = 0;
    delay();
    P56 = 1;
    P57 = 0;
    delay();
    P57 = 1;

    P60 = 0;
    delay();
    P60 = 1;
    P61 = 0;
    delay();
    P61 = 1;
    P62 = 0;
    delay();
    P62 = 1;
    P63 = 0;
    delay();
    P63 = 1;
    P64 = 0;
    delay();
    P64 = 1;
    P65 = 0;
    delay();
    P65 = 1;
    P66 = 0;
    delay();
    P66 = 1;
    P67 = 0;
    delay();
    P67 = 1;

    P70 = 0;
    delay();
    P70 = 1;
    P71 = 0;
    delay();
    P71 = 1;
    P72 = 0;
    delay();
    P72 = 1;
    P73 = 0;
    delay();
    P73 = 1;
    P74 = 0;
    delay();
    P74 = 1;
    P75 = 0;
    delay();
    P75 = 1;
    P76 = 0;
    delay();
    P76 = 1;
    P77 = 0;
    delay();
    P77 = 1;

    while (1)
    {
        P0 = 0x00;
        delay();
        P0 = 0xff;

        P1 = 0x00;
        delay();
        P1 = 0xff;

        P3 = 0x03;          //P3.0/P3.1為仿真口和USB下載口時(shí)不可演示
        delay();
        P3 = 0xff;

        P2 = 0x00;
        delay();
        P2 = 0xff;

        P4 = 0x00;
        delay();
        P4 = 0xff;

        P5 = 0x00;
        delay();
        P5 = 0xff;

        P6 = 0x00;
        delay();
        P6 = 0xff;

        P7 = 0x00;
        delay();
        P7 = 0xff;
    }
}

回復(fù)

使用道具 舉報(bào)

板凳
ID:457374 發(fā)表于 2018-12-28 16:12 | 只看該作者
可以的,需要配置IO口模式,其它和51單片機(jī)一樣的。
#include "reg51.h"

sfr P0M1 = 0x93;
sfr P0M0 = 0x94;

void delay()
{
    int i, j;

    for (i=0; i<1000; i++)
    for (j=0; j<500; j++);
}


void main()
{
   unsigned char temp;
    P0M0 = 0x00;  //配置P0為準(zhǔn)雙向IO
    P0M1 = 0x00;
    while (1)
    {
        temp = P0; //讀取P0狀態(tài)
        delay();
    }
}

回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表