#include#defineucharunsignedchar#defineuintunsignedintsbitled=P2^5;sbitwei=P2^7;sbitduan=P2^6;sbitDQ=P2^2;ucharmazhi_duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};ucharmazhi_wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xff};voiddelayl(uintn){uinti,j;for(i=n;i>0;i--)for(j=114;j>0;j--);}voiddelays(uchari){while(i--);}bitinit_DS18B20()//DS8B20初始化{bitx;DQ=1;//DQ复位delays(8);DQ=0;//单片机将DQ拉低delays(75);DQ=1;//拉高总线delays(15);x=DQ;//延时过后若x=0则初始化成功若x=1则初始化失败delays(5);returnx;}voidwrite_data(uchardat){uchari,temp;temp=dat;DQ=1;for(i=0;i>=1;}}ucharread_data(){uchari,dat;DQ=1;for(i=0;i>=1;DQ=1;//配置为输入if(DQ)dat|=0x80;delays(4);}returndat;}uintreadtemp(){uchartemph,templ;uinttemp;floatwendu;init_DS18B20();write_data(0xcc);//跳过ROMwrite_data(0x44);//启动温度转换//delayl(100);init_DS18B20();write_data(0xcc);//跳过ROMwrite_data(0xBE);//读温度//以下读温度,低八位在前//高8位在后templ=read_data();temph=read_data();temp=(temph<<8)|templ;wendu=temp*0.625+0.5;//温度扩大10倍,四舍五入temp=wendu;//10倍温度returntemp;}voidSTC_init(){P1=0x00;//关闭ledled=0;//锁存wei=0;duan=0;}voiddisplay(ucharweil,ucharduanl,bitdp){wei=1;P0=mazhi_wei[weil-1];wei=0;duan=1;if(dp==1)P0=(mazhi_duan[duanl]|0x80);elseP0=mazhi_duan[duanl];duan=0;}voidmain(){uchari;uintwendu;STC_init();wendu=readtemp();delayl(500);wendu=readtemp();delayl(500);while(1){wendu=readtemp();for(i=0;i<80;i++){display(1,wendu/100,0);delayl(3);display(2,wendu0/10,1);delayl(3);display(3,wendu,0);delayl(3);}}}
2025/12/13 3:17:02 2KB 温度传感
1
在IT领域,尤其是在嵌入式开发、物联网应用或者设备控制等方面,串口通信是一个非常重要的技术。
Qt作为一个跨平台的应用程序开发框架,提供了方便的API用于实现串口读写功能,使得开发者能够在Windows等操作系统上进行相关的编程工作。
本文将详细讲解如何在Qt环境下进行Windows下的串口读写操作。
我们要了解串口通信的基本概念。
串口通信,也称为串行通信,是通过串行数据传输的方式进行设备间的通信。
在Windows系统中,串口通常以COM1、COM2等命名,可以通过波特率、数据位、停止位、校验位等参数进行配置。
在Qt中,串口操作主要依赖于`QSerialPort`类。
`QSerialPort`提供了丰富的成员函数来设置和管理串口,如打开、关闭串口,设置波特率、数据位、停止位、校验位,以及读取和写入数据。
1.**初始化串口**:你需要创建一个`QSerialPort`对象,并指定要使用的串口号。
例如:```cppQSerialPortserial("COM1");```2.**配置串口参数**:接下来,我们需要设置串口的各项参数。
比如,设置波特率为9600,数据位为8,停止位为1,校验位为无校验:```cppserial.setBaudRate(QSerialPort::Baud9600);serial.setDataBits(QSerialPort::Data8);serial.setStopBits(QSerialPort::OneStop);serial.setParity(QSerialPort::NoParity);```3.**打开串口**:确保设置好参数后,可以尝试打开串口:```cppif(!serial.open(QIODevice::ReadWrite)){qDebug()<<"无法打开串口:"<<serial.errorString();return;}```4.**读取数据**:`QSerialPort`提供了`readAll()`函数来读取所有可用的数据,或者使用`read()`函数指定要读取的字节数。
例如:```cppQByteArraydata=serial.readAll();```5.**写入数据**:使用`write()`函数向串口写入数据:```cppQStringmessage="Hello,World!";serial.write(message.toUtf8());```6.**事件驱动**:如果需要持续监听串口数据,可以使用信号和槽机制。
例如,连接`readyRead`信号到相应的处理函数:```cppconnect(&serial,&QSerialPort::readyRead,this,&YourClass::onReadyRead);```7.**关闭串口**:当不再需要使用串口时,记得关闭它:```cppserial.close();```在提供的“Qtwindows下串口读写”示例工程中,可能包含了以上所述的串口操作代码,以及一些错误处理和用户交互的逻辑。
初学者可以通过分析和运行这个示例,更深入地理解Qt在Windows下的串口读写操作。
在实际应用中,可能还需要考虑到线程安全、异常处理、多串口管理等问题,这都需要根据具体需求进行扩展和优化。
Qt的`QSerialPort`类为开发者提供了一种简单易用的方式来实现Windows下的串口通信,通过学习和实践,你可以快速掌握这一技能,为你的项目添加强大的硬件交互能力。
2025/11/30 15:42:27 5KB Windows 串口 demo
1
编译原理龙书答案完整性高第二章2.2ExercisesforSection2.22.2.1Considerthecontext-freegrammar:S->SS+|SS*|aShowhowthestringaa+a*canbegeneratedbythisgrammar.Constructaparsetreeforthisstring.Whatlanguagedoesthisgrammargenerate?Justifyyouranswer.answerS->SS*->SS+S*->aS+S*->aa+S*->aa+a*L={Postfixexpressionconsistingofdigits,plusandmultiplesigns}2.2.2Whatlanguageisgeneratedbythefollowinggrammars?Ineachcasejustifyyouranswer.S->0S1|01S->+SS|-SS|aS->S(S)S|εS->aSbS|bSaS|ε⧗S->a|S+S|SS|S*|(S)answerL={0n1n|n>=1}L={Prefixexpressionconsistingofplusandminussigns}L={Matchedbracketsofarbitraryarrangementandnesting,includesε}L={Stringhasthesameamountofaandb,includesε}?2.2.3WhichofthegrammarsinExercise2.2.2areambiguousanswerNoNoYesYesYes2.2.4Constructunambiguouscontext-freegrammarsforeachofthefollowinglanguages.Ineachcaseshowthatyourgrammariscorrect.Arithmeticexpressionsinpostfixnotation.Left-associativelistsofidentifiersseparatedbycommas.Right-associativelistsofidentifiersseparatedbycommas.Arithmeticexpressionsofintegersandidentifierswiththefourbinaryoperators+,-,*,/.answer1.E->EEop|num2.list->list,id|id3.list->id,list|id4.expr->expr+term|expr-term|termterm->term*factor|term/factor|factorfactor->id|num|(expr)5.expr->expr+term|expr-term|termterm->term*unary|term/unary|unaryunary->+factor|-factorfactor->id|num|(expr)2.2.5Showthatallbinarystringsgeneratedbythefollowinggrammarhavevaluesdivisibleby3.Hint.Useinductiononthenumberofnodesinaparsetree.num->11|1001|num0|numnumDoesthegrammargenerateallbinarystringswithvaluesdivisibleby3?answerproveanystringderivedfromthegrammarcanbeconsideredtobeasequenceconsistingof11,1001and0,andnotprefixedwith0.thesumofthisstringis:sum=Σn(21+20)*2n+Σm(23+20)*2m=Σn3*2n+Σm9*2mItisobviouslycandivisibleby3.No.Considerstring"10101",itisdivisibleby3,butcannotderivedfromthegrammar.Question:anygeneralprove?2.2.6Constructacontext-freegrammarforromannumerals.Note:wejustconsiderasubsetofromannumeralswhichislessthan4k.answerwikipedia:Roman_numeralsviawikipedia,wecancategorizethesinglenomannumeralsinto4groups:I,II,III|IV|V,VI,VII,VIII|IXthengettheproduction:digit->smallDigit|IV|VsmallDigit|IXsmallDigit->I|II|III|εandwecanfindasimplewaytomapromantoarabicnumerals.Forexample:XII=>X,II=>10+2=>12CXCIX=>C,XC,IX=>100+90+9=>199MDCCCLXXX=>M,DCCC,LXXX=>1000+800+80=>1880viatheuppertworules,wecanderivetheproduction:romanNum->thousandhundredtendigitthousand->M|MM|MMM|εhundred->smallHundred|CD|DsmallHundred|CMsmallHundred->C|CC|CCC|εten->smallTen|XL|LsmallTen|XCsmallTen->X|XX|XXX|εdigit->smallDigit|IV|VsmallDigit|IXsmallDigit->I|II|III|ε2.3ExercisesforSection2.32.3.1Constructasyntax-directedtranslationschemethattrans­latesarithmeticexpressionsfrominfixnotationintoprefixnotationinwhichanoperatorappearsbeforeitsoperands;e.g.,-xyistheprefixnotationforx-y.Giveannotatedparsetreesfortheinputs9-5+2and9-5*2.。
answerproductions:expr->expr+term|expr-term|termterm->term*factor|term/factor|factorfactor->digit|(expr)translationschemes:expr->{print("+")}expr+term|{print("-")}expr-term|termterm->{print("*")}term*factor|{print("/")}term/factor|factorfactor->digit{print(digit)}|(expr)2.3.2Constructasyntax-directedtranslationschemethattrans­latesarithmeticexpressionsfrompostfixnotationintoinfixnotation.Giveannotatedparsetreesfortheinputs95-2*and952*-.answerproductions:expr->exprexpr+|exprexpr-|exprexpr*|exprexpr/|digittranslationschemes:expr->expr{print("+")}expr+|expr{print("-")}expr-|{print("(")}expr{print(")*(")}expr{print(")")}*|{print("(")}expr{print(")/(")}expr{print(")")}/|digit{print(digit)}AnotherreferenceanswerE->{print("(")}E{print(op)}E{print(")"}}op|digit{print(digit)}2.3.3Constructasyntax-directedtranslationschemethattrans­latesintegersintoromannumeralsanswerassistantfunction:repeat(sign,times)//repeat('a',2)='aa'translationschemes:num->thousandhundredtendigit{num.roman=thousand.roman||hundred.roman||ten.roman||digit.roman;print(num.roman)}thousand->low{thousand.roman=repeat('M',low.v)}hundred->low{hundred.roman=repeat('C',low.v)}|4{hundred.roman='CD'}|high{hundred.roman='D'||repeat('X',high.v-5)}|9{hundred.roman='CM'}ten->low{ten.roman=repeat('X',low.v)}|4{ten.roman='XL'}|high{ten.roman='L'||repeat('X',high.v-5)}|9{ten.roman='XC'}digit->low{digit.roman=repeat('I',low.v)}|4{digit.roman='IV'}|high{digit.roman='V'||repeat('I',high.v-5)}|9{digit.roman='IX'}low->0{low.v=0}|1{low.v=1}|2{low.v=2}|3{low.v=3}high->5{high.v=5}|6{high.v=6}|7{high.v=7}|8{high.v=8}2.3.4Constructasyntax-directedtranslationschemethattrans­latesromannumeralsintointegers.answerproductions:romanNum->thousandhundredtendigitthousand->M|MM|MMM|εhundred->smallHundred|CD|DsmallHundred|CMsmallHundred->C|CC|CCC|εten->smallTen|XL|LsmallTen|XCsmallTen->X|XX|XXX|εdigit->smallDigit|IV|VsmallDigit|IXsmallDigit->I|II|III|εtranslationschemes:romanNum->thousandhundredtendigit{romanNum.v=thousand.v||hundred.v||ten.v||digit.v;print(romanNun.v)}thousand->M{thousand.v=1}|MM{thousand.v=2}|MMM{thousand.v=3}|ε{thousand.v=0}hundred->smallHundred{hundred.v=smallHundred.v}|CD{hundred.v=smallHundred.v}|DsmallHundred{hundred.v=5+smallHundred.v}|CM{hundred.v=9}smallHundred->C{smallHundred.v=1}|CC{smallHundred.v=2}|CCC{smallHundred.v=3}|ε{hundred.v=0}ten->smallTen{ten.v=smallTen.v}|XL{ten.v=4}|LsmallTen{ten.v=5+smallTen.v}|XC{ten.v=9}smallTen->X{smallTen.v=1}|XX{smallTen.v=2}|XXX{smallTen.v=3}|ε{smallTen.v=0}digit->smallDigit{digit.v=smallDigit.v}|IV{digit.v=4}|VsmallDigit{digit.v=5+smallDigit.v}|IX{digit.v=9}smallDigit->I{smallDigit.v=1}|II{smallDigit.v=2}|III{smallDigit.v=3}|ε{smallDigit.v=0}2.3.5Constructasyntax-directedtranslationschemethattrans­latespostfixarithmeticexpressionsintoequivalentprefixarithmeticexpressions.answerproduction:expr->exprexprop|digittranslationscheme:expr->{print(op)}exprexprop|digit{print(digit)}ExercisesforSection2.42.4.1Constructrecursive-descentparsers,startingwiththefollow­inggrammars:S->+SS|-SS|aS->S(S)S|εS->0S1|01Answer1)S->+SS|-SS|avoidS(){switch(lookahead){case"+":match("+");S();S();break;case"-":match("-");S();S();break;case"a":match("a");break;default:thrownewSyntaxException();}}voidmatch(Terminalt){if(lookahead=t){lookahead=nextTerminal();}else{thrownewSyntaxException()}}2)S->S(S)S|εvoidS(){if(lookahead=="("){S();match("(");S();match(")");S();}}3)S->0S1|01voidS(){switch(lookahead){case"0":match("0");S();match("1");break;case"1"://match(epsilon);break;default:thrownewSyntaxException();}}ExercisesforSection2.62.6.1ExtendthelexicalanalyzerinSection2.6.5toremovecom­ments,definedasfollows:Acommentbeginswith//andincludesallcharactersuntiltheendofthatline.Acommentbeginswith/*andincludesallcharactersthroughthenextoccurrenceofthecharactersequence*/.2.6.2ExtendthelexicalanalyzerinSection2.6.5torecognizetherelationaloperators.2.6.3ExtendthelexicalanalyzerinSection2.6.5torecognizefloat­ingpointnumberssuchas2.,3.14,and.5.AnswerSourcecode:commit8dd1a9aCodesnippet(src/lexer/Lexer.java):publicTokenscan()throwsIOException,SyntaxException{for(;;peek=(char)stream.read()){if(peek==''||peek=='\t'){continue;}elseif(peek=='\n'){line=line+1;}else{break;}}//handlecommentif(peek=='/'){peek=(char)stream.read();if(peek=='/'){//singlelinecommentfor(;;peek=(char)stream.read()){if(peek=='\n'){break;}}}elseif(peek=='*'){//blockcommentcharprevPeek='';for(;;prevPeek=peek,peek=(char)stream.read()){if(prevPeek=='*'&&peek=='/'){break;}}}else{thrownewSyntaxException();}}//handlerelationsignif("".indexOf(peek)>-1){StringBufferb=newStringBuffer();b.append(peek);peek=(char)stream.read();if(peek=='='){b.append(peek);}returnnewRel(b.toString());}//handlenumber,notypesensitiveif(Character.isDigit(peek)||peek=='.'){BooleanisDotExist=false;StringBufferb=newStringBuffer();do{if(peek=='.'){isDotExist=true;}b.append(peek);peek=(char)stream.read();}while(isDotExist==true?Character.isDigit(peek):Character.isDigit(peek)||peek=='.');returnnewNum(newFloat(b.toString()));}//handlewordif(Character.isLetter(peek)){StringBufferb=newStringBuffer();do{b.append(peek);peek=(char)stream.read();}while(Character.isLetterOrDigit(peek));Strings=b.toString();Wordw=words.get(s);if(w==null){w=newWord(Tag.ID,s);words.put(s,w);}returnw;}Tokent=newToken(peek);peek='';returnt;}ExercisesforSection2.82.8.1For-statementsinCandJavahavetheform:for(exprl;expr2;expr3)stmtThefirstexpressionisexecutedbeforetheloop;itistypicallyusedforinitializ­ingtheloopindex.Thesecondexpressionisatestmadebeforeeachiterationoftheloop;theloopisexitediftheexpressionbecomesO.Theloopitselfcanbethoughtofasthestatement{stmtexpr3;}.Thethirdexpressionisexecutedattheendofeachiteration;itistypicallyusedtoincrementtheloopindex.Themeaningofthefor-statementissimilartoexpr1;while(expr2){stmtexpr3;}DefineaclassForforfor-statements,similartoclassIfinFig.2.43.AnswerclassForextendsStmt{ExprE1;ExprE2;ExprE3;StmtS;publicFor(Exprexpr1,Exprexpr2,Exprexpr3,Stmtstmt){E1=expr1;E2=expr2;E3=expr3;S=stmt;}publicvoidgen(){E1.gen();Labelstart=newLable();Lalelend=newLable();emit("ifFalse"+E2.rvalue().toString()+"goto"+end);S.gen();E3.gen();emit("goto"+start);emit(end+":")}}2.8.2TheprogramminglanguageCdoesnothaveabooleantype.ShowhowaCcompilermighttranslateanif-statementintothree-addresscode.AnswerReplaceemit("isFalse"+E.rvalue().toString()+"goto"+after);withemit("ifNotEqual"+E.rvalue().toString()+"0goto"+after);oremit("isNotEqualZero"+E.rvalue().toString()+"goto"+after);
2025/11/27 8:37:48 658KB 龙书答案 完整性高
1
以时间程序为例介绍了linux下C网络编程的TCP/UDP,服务器端/客户端的基本用法,socket,inet-ptoh,hton,bind,listen,acceept,connect,read,write,快速入门,超实用
2025/11/22 4:04:07 17KB linux C 网络编程
1
java读取doc、docx、slx、xlsx等word和excel文件,方法都集合在Read类中,返回一个HTML路径,可以用在WEB开发上,功能强大
2025/10/20 18:48:13 31KB java doc、docx slx、 xlsx
1
使用.c文件read函数读取返回的16进制值就可以直接获得传感器的温度,本程序为hal库开发主要是自己在做练习题的时候没有hal版驱动所以重新弄了一个。
2025/10/1 0:48:42 275KB stm32 嵌入式
1
Nachos实验(操作系统课程设计)共四个实验,每个实验是单独分离开,有代码,有详细文档。
实验1#内核线程调度策略设计设计了两个静态(FCFS,静态优先数),两个动态(动态优先数,彩票算法)。
实验2#进程同步设计一个Haro样式的条件变量,通过实现采用该条件变量的生产者消费者问题管程和哲学家问题管程,用多个使用管程的协作线程验证其正确性。
实验3#用户进程和空间管理设计实现了多道程序共驻内存,用户程序并发执行,实现了多个系统调用(Fork,Exec,Join,Exit,Wait,Halt,Create,Open,Read,Write,Close,Yield,,实现了一个简单的shell程序,并实现了shell上的用户程序的并发,输出重定向功能。
本实验中采用了进程同步的功能。
实现了进程表,使用父子进程关系表实现父子进程关系。
实验4#文件系统扩展设计使Nachos文件的长度可以扩展。
扩充Nachos文件的最大容量。
2025/9/20 9:34:58 2.13MB Nachos实验 操作系统课程设计
1
笔趣阁小说下载阅读器是一个在线电子书阅读器,其实严谨的来讲是一个在线下载本地查看的小说阅读器,可以在线获取小说简洁,点击阅读以后会把txt小说下载到本地SD卡目录下的read/record文件夹中,下次阅读无需联网即可阅读。
项目有一些常规的很方便的功能,例如:字体大小设置、亮度设置、夜间模式、书签管理、进度转跳等,翻页使用的是贝塞尔曲线形式,,效果流畅没有任何卡顿,项目内的小说数据直接调用笔趣阁(http://www.biquge.com/)数据,使用jsoup对html页面进行解析,对txt大文件有良好的支持,是个不错的小说阅读器源码。
 
2025/8/24 6:39:17 5.69MB 安卓源码-小说阅读器
1
如果采用官方mysql5.6,推荐该0.56版本,用高版本会出现super_read_only问题,虽然包名带el6,centos7也可使用
2025/8/20 7:51:11 112KB mysql mha4mysql mysql5.6 mha
1
简介:
在.NET框架中,C#语言的类(class)属于引用类型。
这意味着当你声明一个类的实例时,实际上是在堆上创建一个对象,并在栈上创建一个引用指向这个对象。
因此,当你将对象作为参数传递给函数时,实际上是传递了这个引用的副本,而不是对象本身。
这就是所谓的"传引用"或"按引用传递"。
让我们深入探讨一下这个问题,以标题和描述中给出的代码为例:```csharpclass Program{ static void Main(string[] args) { TestClass objA = new TestClass(); objA.Name = "I am ObjA"; Console.WriteLine(String.Format("In Main:{0}", objA.Name)); TestFun(objA); Console.WriteLine(String.Format("In Main:{0}", objA.Name)); Console.Read(); } static void TestFun(TestClass obj) { obj.Name = "I am be modified in TestFun"; Console.WriteLine(String.Format("In TestFun:{0}", obj.Name)); } public class TestClass { public string Name { get; set; } }}```在这个例子中,`TestFun`函数接收到`objA`的引用副本`obj`。
当在`TestFun`中修改`obj.Name`时,实际上是修改了`objA`引用的对象,因为它们都指向同一个堆上的实例。
因此,`Main`函数中再次打印`objA.Name`时,值已经被修改为"I am be modified in TestFun"。
然而,如果我们更改`TestFun`的实现:```csharpstatic void TestFun(TestClass obj){ TestClass objB = new TestClass(); obj = objB; obj.Name = "I am ObjB"; Console.WriteLine(String.Format("In TestFun:{0}", obj.Name));}```这里我们创建了一个新的`TestClass`实例`objB`,然后让`obj`引用`objB`。
虽然在`TestFun`内部`obj`的值改变了,但这不会影响`Main`函数中的`objA`,因为`objA`仍然指向原始的`TestClass`实例。
所以,`Main`函数中的`objA.Name`输出仍然是"I am ObjA",因为`objA`并没有被修改指向新创建的`objB`。
这个现象可以用内存模型来解释,就像描述中提到的那样。
在调用`TestFun`时,`objA`的地址被复制到`obj`,但是`objA`本身并未改变。
在`TestFun`中,`obj`被重新分配给`objB`的地址,但`objA`仍然指向原始对象,所以`Main`中的`objA`不会受到影响。
C#中的对象参数传递特性对于理解和调试代码非常重要。
理解这种行为可以帮助我们避免意外地修改了原本不想修改的对象,同时也能有效地利用引用传递来共享和修改数据。
在编写函数时,要清楚地知道参数是值类型(value type,如int、struct)还是引用类型(reference type,如class),因为这将直接影响到参数的处理方式和函数的行为。
2025/6/15 20:02:36 44KB
1
共 104 条记录 首页 上一页 下一页 尾页
在日常工作中,钉钉打卡成了我生活中不可或缺的一部分。然而,有时候这个看似简单的任务却给我带来了不少烦恼。 每天早晚,我总是得牢记打开钉钉应用,点击"工作台",再找到"考勤打卡"进行签到。有时候因为工作忙碌,会忘记打卡,导致考勤异常,影响当月的工作评价。而且,由于我使用的是苹果手机,有时候系统更新后,钉钉的某些功能会出现异常,使得打卡变得更加麻烦。 另外,我的家人使用的是安卓手机,他们也经常抱怨钉钉打卡的繁琐。尤其是对于那些不太熟悉手机操作的长辈来说,每次打卡都是一次挑战。他们总是担心自己会操作失误,导致打卡失败。 为了解决这些烦恼,我开始思考是否可以通过编写一个全自动化脚本来实现钉钉打卡。经过一段时间的摸索和学习,我终于成功编写出了一个适用于苹果和安卓系统的钉钉打卡脚本。
2024-04-09 15:03 15KB 钉钉 钉钉打卡