初学单片机,学写了个程序,结果有错误,找了一下午也没找到

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了初学单片机,学写了个程序,结果有错误,找了一下午也没找到相关的知识,希望对你有一定的参考价值。

#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit duanxian=P0; //段显
sbit weix1=P2^2;
sbit weix2=P2^3;
sbit weix3=P2^4; //位显
uchar disnum,key,temp,delay;
uchar code lea[]=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;

void delay() //延时程序

uchar i,j;
for(i=20;i>0;i--)
for(j=248;j>0;j--);

void main()

weix1=0;
weix2=0;
weix3=0;
while(1)

P1=0xf0;
temp=P1;
temp=temp&0xf0;//按位与
if(temp!=0xf0) //若temp不等于0xf0

delay(); //延时10ms
if(temp!=0xf0)

temp=P1;
temp=temp|0x0f;//按位或,使低四位置1
P3=temp;
key=P1;
swith(key)

case 0x77 : disnum=1;
break;
case 0x7b : disnum=2;
break;
case 0x7d : disnum=3;
break;
case 0x7e : disnum=4;
break;
case 0xb7 : disnum=5;
break;
case 0xbb : disnum=6;
break;
case 0xbd : disnum=7;
break;
case 0xbe : disnum=8;
break;
case 0xc7 : disnum=9;
break;
case 0xcb : disnum=10;
break;
case 0xcc : disnum=11;
break;
case 0xcd : disnum=12;
break;
case 0xd7 : disnum=13;
break;
case 0xdb : disnum=14;
break;
case 0xdc : disnum=15;
break;
case 0xdd : disnum=16;
break;





P0=lea[disnum];


错误显示如下:
Build target 'Target 1'
compiling jianpan.c...
JIANPAN.C(13): error C231: 'delay': redefinition
JIANPAN.C(17): error C231: 'delay': redefinition
JIANPAN.C(30): error C211: call not to a function
Target not created

第8行,定义变量时,有delay,可下面又是延时子程序名,重复了。把第8行定义变量中的delay删掉。 参考技术A delay又是变量,又是函数,所以是重复定义

Python 写了个小程序,耗时一天,结果才100多行

from selenium import webdriver
import selenium.webdriver.support.ui as ui
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException,WebDriverException
import selenium.webdriver.support.expected_conditions as EC
import time
from selenium.webdriver.chrome.options import Options
import io
import os
import re
import urllib2
from datetime import datetime
projectList=[*,**]
serverURL=****
userProfile=C:/Users/***a
consoleText=consoleText
logPath=**
def write_file(data,fileName):
    file_name = logPath+fileName+r.txt
    append_write = a
    if os.path.exists(file_name):
        append_write = w
    f = open(file_name, append_write)
    f.writelines(data)
    f.close()
    return file_name
def get_latest_version(driver,projectList,serverURL):
    version=[]
    for i in projectList:
        ### get latest version ID. Such as 31,32
        url = serverURL+str(i)
        driver.get(url)
        click_submit(driver)
        attr = driver.find_elements_by_css_selector("div.build-icon>a")[0].get_attribute("href")
        buildId = attr.split(/)[-2]
        ### get log content with encoding utf-8
        url = url+r/+buildId+r/+consoleText
        driver.get(url)
        time.sleep(2)
        content = driver.page_source.encode("utf-8")
        ### write file to local, named with like rhel-buildId
        ### list format: os, logPath(local),buildId
        version.append([i,write_file(content,i+#+buildId),buildId])
    return version
def click_submit(driver):
    if len(driver.find_elements_by_css_selector("input[name=‘j_password‘]")) > 0:
        driver.find_element_by_css_selector("span[name=‘Submit‘] button").click();
def get_test_summary(file_obj):
    isSummary = False
    result = []
    for line in file_obj:
        if not isSummary:
            if Test Summary in line:
                isSummary = True
        elif End of Summary in line:
            break
        else:
            result.append(line)
    return result
def get_common_issues(list1,list2):
    common_issues = []
    result = [l for l in list1 if l in list2 and Failed:  0 not in l]
    for ele in result:
        if ele != \r\n and ele != \n:
            common_issues.append(ele)
            print ele
    return common_issues
def get_server_log_path(file_obj):
    for line in file_obj:
        if GQL Log is located at in line:
            return line.split()[-1]
def get_summary_list(version):
    summary_list = []
    for os_ele in version:
        file_obj = open(os_ele[1],r)
        summary_list.append(get_test_summary(file_obj))
        os_ele.append(get_server_log_path(file_obj))
        file_obj.close()
    return summary_list
def write_summary_log(summary_log_name, common_issues,baseUrl):
    for com_is in common_issues:
        com_is = com_is.split(:)[0]
        try:
            response = urllib2.urlopen(baseUrl+r/+com_is)
            case_log_path = write_file(response,com_is+datetime.today().strftime(%Y-%m-%d))
            #print ‘case log path:‘,case_log_path
        except:
            continue
        f = open(case_log_path,r)
        data = f.read()
        f.close()
        match = re.findall(r(?:(?!Test Case: ).)*Test Case: Fail,data,re.DOTALL)
        for i in match: 
            if os.path.exists(summary_log_name):
                append_write = a
            else:
                append_write = w
            f = open(summary_log_name,append_write)
            f.writelines(#########+com_is+#########)
            f.write(\r\n)
            if i.startswith(est Case:):
                i = i[i.find(\n):]
            for parsed in [line for line in i.split(\n) if line.strip() !=‘‘]:
                f.writelines(parsed)
            f.write(\r\n)
            f.close()
    print Summary file put in , summary_log_name
options = webdriver.ChromeOptions() 
options.add_argument(--user-data-dir=+userProfile)
driver = webdriver.Chrome(executable_path=rC:/Python27/chromedriver.exe,chrome_options=options)
version = get_latest_version(driver,projectList,serverURL)
driver.quit()
summary_list = get_summary_list(version)
common_issues = get_common_issues(summary_list[0],summary_list[1])
baseUrl = version[0][-1]
print baseUrl
summary_log_name = logPath + datetime.today().strftime(%Y-%m-%d) + r.txt
if os.path.exists(summary_log_name):
    os.remove(summary_log_name)
write_summary_log(summary_log_name, common_issues,baseUrl)

 

以上是关于初学单片机,学写了个程序,结果有错误,找了一下午也没找到的主要内容,如果未能解决你的问题,请参考以下文章

寒假九

单片机是ATmega48的,写了个24C02的程序,但是程序一直没能进去,麻烦大侠们帮忙看看哪里出了问题。

maven依赖引入失败,找了一下午

闲的无聊写了个很(wu)有(liao)意(dao)思(bao)的程序

下午没事干,写了个仿CSDN的静态博客页面

单片机程序100-300例(付注释详解)