精华内容
下载资源
问答
  • 单片机编程技巧单片机编程技巧单片机编程技巧单片机编程技巧单片机编程技巧
  • 本篇文章主要讨论单片机编程技巧问题。助你在单片机学习中少走弯路。
  • 单片机编程技巧100例
  • 单片机编程技巧From the desk of a brilliant weirdo #1:从辉煌的怪胎#1的桌子上: Thank you for taking the time to check out this article. It doesn’t matter where you’re coming from (Codegiant, Hacker ...

    单片机编程技巧

    From the desk of a brilliant weirdo #1:

    从辉煌的怪胎#1的桌子上:

    Thank you for taking the time to check out this article. It doesn’t matter where you’re coming from (Codegiant, Hacker News, Reddit, or some other place), I always appreciate every reader who lands on my articles.

    感谢您抽出宝贵时间阅读本文。 无论您来自哪里(Codegiant,Hacker News,Reddit或其他地方)都无所谓,我总是感谢所有阅读我的文章的读者。

    Now that I’ve coaxed you into reading this article, let’s get down to brass tacks.

    现在,我已诱使您阅读本文,让我们开始讨论。

    Whenever you’re just starting out with software development or simply want to uplevel your programming skills, you’ll need the right info resources to achieve your goals.

    每当您刚开始软件开发或只是想提高您的编程技能时,就需要正确的信息资源来实现您的目标。

    In this article, I’ve listed 22 of the best YouTube channels for improving your programming skills. Some are geared towards beginners while others focus on advanced topics.

    在本文中,我列出了22个最佳YouTube频道,可提高您的编程技能。 有些面向初学者,而另一些则针对高级主题。

    So, if you consider yourself an experienced programmer, you can jump over to the last section where you’ll find all the 22 YouTube channels.

    因此,如果您认为自己是一位经验丰富的程序员,则可以跳到最后一部分,在该部分您将找到所有22个YouTube频道。

    If you are a beginner developer, however, I recommend that you go through each section of this article as we’ll talk about coding in general, programming skills, your computer programming resume, job opportunities, and some of the most in-demand programming languages.

    但是,如果您是新手开发人员,建议您仔细阅读本文的每个部分,因为我们将讨论常规编码,编程技巧,计算机编程履历,工作机会以及一些需求最大的编程语言。

    Without further ado:

    无需再费周折:

    什么是编码及其工作方式? (What Is Coding And How Does It Work?)

    Coding is the end result of a specific set of actions triggered to create a tangible result, whether it is a web page, an app, a video, or just an image on your screen.

    编码是触发一组特定操作的最终结果,这些操作触发创建有形结果,无论是网页,应用程序,视频还是屏幕上的图像。

    The great thing about computer coding (or programming) is that you can have a big idea and actually code it out into reality. And it doesn’t cost much, barring some time and effort on your side.

    关于计算机编码(或编程)的伟大之处在于,您可以有一个很大的想法并将其实际编码为现实。 而且花费不多,无需您花费一些时间和精力。

    Many non-tech people consider the definition of a computer programmer to be someone who just makes programs. Although that’s partly true, partly not, it’s a mistake. Managers believe that the more lines of code a programmer can produce a month, the more creative he will be — another mistake. You can’t put a developer into a cubicle, set a deadline, ask him to work for 8–9 hours straight, and expect a top-notch quality software at the end.

    许多非技术人员认为计算机程序员的定义是仅仅编写程序的人。 尽管部分正确,部分错误,但这是一个错误。 经理们认为,程序员一个月可以生产的代码行越多,他的创造力就越多-这是另一个错误。 您不能将开发人员放到一个隔间中,设置截止日期,要求他连续工作8–9个小时,并期望最后使用一流的软件。

    Instead of thinking about the programs a developer composes, one should consider the possible computations evoked by the developed program. “Designing a set of computations” is a more accurate description of what programmers actually do.

    与其考虑开发人员编写的程序,不如考虑开发人员程序可能引起的计算。 “设计一组计算”是对程序员实际行为的更准确描述。

    One can also imagine programmers as writers that have to think and write carefully, because the readers (the computers) take what the programmers write literally.

    人们还可以将程序员想象为必须认真思考和写作的作家,因为读者(计算机)接受了程序员的字面意思。

    什么是最有价值的计算机程序员技能? (What Are The Most Valuable Computer Programmer Skills?)

    Image for post

    Many non-tech folks believe that programming is all about acquiring technical skills. I believe that being a developer requires more than just knowing how to code. To make it in the software development world, you’ll need to dig up some creativity and inject it into your coding skills. The ability to think analytically is highly valued among developers as well.

    许多非技术人员都认为编程就是获得技术技能。 我相信,成为开发人员不仅需要知道如何编码,还需要更多。 要在软件开发领域中做到这一点,您需要挖掘一些创造力,并将其注入您的编码技能中。 开发人员也高度重视分析思维的能力。

    One of the most essential skills a developer can have isn’t actually technical, it’s social, and that is empathy. Lack of empathy inevitably leads to poor communication (barring you are a narcissist, sociopath, or psychopath and therefore can be charming as hell). On the other hand, being able to put empathy into practice will, without doubt, boost your career opportunities.

    开发人员可以拥有的最基本技能之一不是技术,而是社交,这就是同理心。 缺乏同理心会导致沟通不畅(除非您是自恋者,社会变态者或精神变态者,因此可能像地狱般迷人)。 另一方面,将同情心付诸实践无疑会增加您的职业机会。

    When it comes to planning software, developers should know how to use models and flowcharts to convey instructions clearly.

    规划软件时,开发人员应该知道如何使用模型和流程图清楚地传达指令。

    Designing and creating applications. Depending on the project, this can take from a couple of weeks to months and sometimes even years to complete.

    设计和创建应用程序。 根据项目的不同,这可能需要几个星期到几个月甚至几个月的时间才能完成。

    Writing programs. As simple as that.

    编写程序。 就如此容易。

    Update and expand existing programs. Most times, you’ll need to modify and update existing programs with extra features.

    更新和扩展现有程序。 大多数时候,您需要使用其他功能来修改和更新现有程序。

    Debugging code. Yup.

    调试代码。 对。

    Simplify programming. Developers may also use software tools to automate a part of their development process in order to simplify and speed up the workflow.

    简化编程。 开发人员还可以使用软件工具来自动化其开发过程的一部分,以简化和加快工作流程。

    如何成为计算机程序员? (How To Become a Computer Programmer?)

    Image for post

    Showing up and practicing your programming skills seem to be the main ingredients to getting better at programming and coding. You gotta be programming in your spare time; you gotta be obsessed with it. Load yourself with patience because becoming a skilled coder takes years. And anyone who is telling you that you can learn and become good at coding in a month is probably trying to sell you something.

    展现和练习编程技巧似乎是提高编程和编码水平的主要因素。 您必须在业余时间进行编程。 你必须沉迷于它。 变得耐心一点,因为成为一名熟练的编码员需要数年时间。 任何告诉您可以在一个月内学习并变得精通的人都可能想向您推销产品。

    Senior developers have all adopted common traits and basic coding skills that have helped them to rise in the hierarchy during their programming careers. Here are some valuable skills needed for you to be a senior developer:

    高级开发人员都采用了共同的特征和基本的编码技能,这有助于他们在编程生涯中的层次结构中不断发展。 成为高级开发人员需要以下一些宝贵的技能:

    One, being able to easily explain tech stuff to non-technical people.

    第一,能够轻松地向非技术人员解释技术知识。

    Two, being able to come up with accurate estimates.

    第二,能够提出准确的估计。

    Three, willingness to roll up their sleeves and do some grunt work.

    第三,愿意卷起袖子,做些艰苦的工作。

    Four, knowing when to raise an issue to upper management.

    第四,知道什么时候向高层管理人员提出问题。

    Five, the ability to mentor junior developers.

    五,指导初级开发人员的能力。

    Six, vast knowledge of the technicalities for their domain.

    六,对其领域的技术有广泛的了解。

    了解语言的工作原理 (Understand how the language works)

    Focus on one language while learning. Having your focus split between two or three languages will discombobulate you.

    在学习时专注于一种语言。 将您的注意力集中在两种或三种语言之间会分散您的注意力。

    It becomes obvious when a programmer doesn’t have a good understanding of the programming language he’s using. He’ll try to solve problems by following the logic of other languages and thus litter the code with unnecessary statements that can otherwise be reduced to fewer lines.

    当程序员对所使用的编程语言没有很好的了解时,就会变得很明显。 他将尝试通过遵循其他语言的逻辑来解决问题,从而用不必要的语句来填充代码,否则这些语句可以减少为更少的行。

    Also, you must know how to organize code into a system that makes sense. Creating rigid classes, schemas, and hierarchies require you to first think them through. Design can be a broad topic so I won’t cover much, but if you wish to read more, head over here.

    另外,您必须知道如何将代码组织到有意义的系统中。 创建严格的类,模式和层次结构要求您首先仔细考虑它们。 设计可能是一个广泛的主题,所以我不会涉及太多,但是如果您想了解更多信息,请转到此处

    Poorly designed software lacks well-defined concepts, and its responsibilities are vague. Good software, on the other hand, comes with clear concepts and responsibilities. Take a look at mathematicians and physicists. They spend a huge amount of time trying to develop a clear definition of something because that will allow them to understand the truth about it. Developers should take a similar approach and spend a considerable amount of time brainstorming before writing code. Yes, this might be controversial to Agile but you gotta do what you gotta do.

    设计欠佳的软件缺乏定义明确的概念,其职责含糊不清。 另一方面,好的软件带有明确的概念和职责。 看看数学家和物理学家。 他们花费大量时间来尝试为某事物建立清晰的定义,因为这将使他们能够理解其真实性。 开发人员应采用类似的方法,并在编写代码之前花大量时间进行头脑风暴。 是的,这可能对敏捷有争议,但是您必须做您必须做的事。

    It’s better to sit down with the dev team initially and outline all the required tasks than to go through 10 rounds of code reviews later.

    最好先与开发团队坐下来,概述所有必需的任务,而不是随后进行10轮代码审查。

    Perhaps the best way to learn about design is to write and study many programs written by experienced programmers. As you gain more coding experience, you’ll, without doubt, enhance your design skills and expand your knowledge.

    学习设计的最佳方法也许就是编写和研究由经验丰富的程序员编写的许多程序。 随着您获得更多的编码经验,毫无疑问,您将提高您的设计技能并扩展您的知识。

    Good programmers ask questions like:

    优秀的程序员会提出以下问题:

    • What’s the goal of this function?

      此功能的目的是什么?
    • How can I explain this data structure to my teammates?

      我如何向队友解释此数据结构?
    • Can this function represent two standalone tasks?

      此功能可以代表两个独立的任务吗?
    • What’s the responsibility of this snippet of code?

      此代码段的职责是什么?
    • What should I include in the public interface?

      我应该在公共界面中包含什么?

    您的计算机编程简历(+工作机会) (Your Computer Programming Resume (+ Job Opportunities))

    Image for post

    Most people think that you need a diploma from Harvard or universities alike to be considered for a job in big tech companies. Although that may be partially true (not always though, it seems Apple and Google no longer require you to have a college degree), some companies prefer the opposite, or at least don’t want you to be coming for Harvard, Oxford, Stanford, etc.

    大多数人认为,要想在大型科技公司工作,就需要哈佛或大学的文凭。 尽管这可能部分是正确的(虽然并非总是如此,但似乎苹果和Google不再要求您拥有大学学位),但有些公司更喜欢相反的做法,或者至少不希望您来哈佛,牛津,斯坦福大学等

    There are CEOs out there looking for developers that are qualified but not overly qualified… hard workers, being on time, but also leaving at the stroke of 5. Such CEOs consider Ivy League schools to be a red flag. Big resumes are also a red flag. That’s because developers coming from such schools can’t get off their high horse, question whether every decision is optimal, and are always hungry for praise, recognition, and “interesting work.”

    那里有CEO在寻找合格但不合格的开发人员……努力工作,准时,离职的人只有5人。这些CEO认为常春藤盟校是一个危险信号。 大型简历也是一个危险信号。 这是因为来自这样的学校的开发人员不能放任自流,质疑每个决定是否都是最优的,并且总是渴望获得赞扬,认可和“有趣的工作”。

    Instead, these CEOs are looking for loyal people who know how to take orders without questioning, and are ready to do the work, day in and day out, because they need the paycheck at the end of the month.

    相反,这些首席执行官正在寻找忠诚的人,他们知道如何毫无疑问地接受订单,并准备日复一日地完成工作,因为他们需要月底的薪水。

    At a glance, this might seem quite controversial. Yet, there are developers out there who don’t want to become millionaire CTOs at the age of 30. Instead, they are satisfied with what they have on their plate: a steady job, fair pay, and that’s about it. Some companies with that kind of culture say that they have produced a 100% employee retention rate which means developers are happy with their work environment.

    乍一看,这似乎很有争议。 但是,有些开发人员不想在30岁时成为百万富翁CTO。相反,他们对自己的工作条件感到满意:一份稳定的工作,合理的薪水,仅此而已。 一些具有这种文化的公司表示,他们产生了100%的员工保留率,这意味着开发人员对他们的工作环境感到满意。

    现在让我们谈谈您的简历。 (Let’s talk about your resume now.)

    Image for post

    So, what should you list on your resume?

    那么,您应该在简历中列出什么?

    Proficiency in programming languages is, ostensibly, a vital thing to include. Always remember that companies are getting tens, hundreds, even thousands of applications a month. All of which say “I can do X.” The thing is skill level varies between each applicant. You should describe your coding experience and give examples of successful projects you’ve completed.

    表面上,熟练编程语言显然是至关重要的。 永远记住,公司每月收到数十,数百甚至数千个应用程序。 所有人都说“我可以做X”。 问题是每个申请人之间的技能水平是不同的。 您应该描述您的编码经验,并举例说明您已完成的成功项目。

    When listing your most valuable programming skills, there are a couple of things you need to know in order to have a fully optimized programming resume.

    当列出您最有价值的编程技能时,您需要了解几件事才能拥有完全优化的编程履历。

    1. Before sending your resume, always go through the job description a couple of times and try to understand what is relevant to the job you are applying for. Then make yourself relevant to the job.

      发送简历之前,请务必仔细浏览一下职位描述,并尝试了解与您所申请的职位相关的内容。 然后使自己与工作相关。
    2. Always be honest with yourself. Don’t list programming languages you don’t know because they are mentioned in the job description. Don’t tell them you have 5 years of experience when you only have 4 years and 1 month.

      永远对自己诚实。 不要列出您不知道的编程语言,因为它们在职位描述中被提及。 当您只有4年零1个月时,请不要告诉他们您有5年的经验。
    3. Place your programming skills (languages) right at the top, below the header.

      将您的编程技巧(语言)放在标题顶部的顶部。
    4. List your most advanced coding skills first, then in the middle list the ones you are least experienced with, and at the end, list the programming skills you have a decent experience with.

      首先列出您最高级的编码技能,然后在中间列出您最不熟悉的编程技能,最后列出您具有良好经验的编程技能。
    5. Create horizontal categories instead of vertical ones. This eliminates the blank space on your resume while remaining aesthetically pleasing.

      创建水平类别,而不是垂直类别。 这样可以消除简历上的空白,同时保持美观。

    In your resume, except for talking about what you bring to the table, you can also mention what you’re looking for in an employer. You’ll thus earn the respect you are looking for if you get the job.

    在简历中,除了谈论要带到餐桌上的东西以外,您还可以提及自己在雇主中寻找的东西。 这样一来,您将获得所寻求的尊重。

    Also, avoid using phrases that everybody else is using. Don’t be afraid to infuse your CV with some personality. You’ll thus stand out. Not everybody will like your personality, but those that do will adore you. Try to be specific in your writing. Instead of “extensive experience,” say “5 years and 6 months of experience.” Instead of saying “Y number of successful projects,” say “Y amount of successful projects that helped us achieve A, B, and C.” You get the drill.

    另外,请避免使用其他人都在使用的短语。 不要害怕给自己的简历注入一些个性。 您将因此脱颖而出。 并非每个人都会喜欢您的个性,但每个人都会喜欢您。 尝试在写作中做到具体。 与其说“丰富的经验”,不如说是“ 5年6个月的经验”。 与其说“ Y个成功的项目数”,不如说“帮助我们实现A,B和C的成功项目数”。 你钻了。

    Quite often, though, a seasoned developer will have so much experience and projects under his belt that his resume would spread 10 pages long if he were to list everything. Try to identify what’s most relevant to the job you’re applying for and list those skills and projects that will make you most relevant.

    但是,一个经验丰富的开发人员经常会在他的领导下拥有如此丰富的经验和项目,以至于如果他列出所有内容,他的简历将长达10页。 尝试找出与您所申请的工作最相关的内容,并列出使您最相关的技能和项目。

    It’s a good idea, although laborious and tiresome, to rewrite your resume for each job you are applying for. Thus you’ll be able to fine-tune some details to look like a great fit in the eyes of the people hiring you. Never send a generic CV; you won’t stand out; you’ll look like “just the next boring applicant in the list,” and your chances of getting hired will be significantly reduced.

    这是一个好主意,尽管很费力又累人,但为您要申请的每份工作重写简历。 这样,您就可以微调一些细节,使其看起来非常适合雇用您的人们。 切勿发送通用简历; 你不会脱颖而出; 您将看起来像“只是列表中的下一个无聊的申请人”,并且您被录用的机会将大大减少。

    You can also try a different approach when applying for online coding jobs. Some developers send in their “normal” CV (listing computer programming skills, education, experience, etc.) along with another one, a “personal” CV, that explains their previous works on keynote slides with pictures of algorithms and tech stuff. This also wakes up the reader if your CV comes after a batch of 500 boring resumes.

    您也可以在申请在线编码工作时尝试其他方法。 一些开发人员发送他们的“普通”简历(列出计算机编程技能,学历,经验等),以及另一个“个人”简历,用算法和技术图片在主题幻灯片上解释他们以前的工作。 如果您的简历在500份无聊的简历之后出现,这也会唤醒阅读器。

    Remember, you have to capture your reader’s attention almost immediately. The attention span of the average person these days is about 8 seconds. Given that your resume will be read by people reading CVs all day long, they’ll probably have a shorter attention span, around 5 seconds, I’d say.

    请记住,您必须立即吸引读者的注意力。 这些天普通人的注意力跨度约为8秒。 鉴于全天候阅读简历的人们都会阅读您的简历,所以他们的注意力跨度可能会较短,大约为5秒。

    Here some websites that feature different types of online coding jobs:

    以下是一些具有不同类型的在线编码工作的网站:

    最受欢迎的语言(Most In Demand Languages)

    Image for post

    Having a solid foundation in at least two languages will increase your job opportunities by 2X. Most developers select a programming field they are genuinely interested in and then focus on learning the languages that shepherd that area.

    拥有至少两种语言的坚实基础将使您的工作机会增加2倍。 大多数开发人员选择他们真正感兴趣的编程领域,然后集中精力学习掌握该领域的语言。

    According to Indeed.com’s job postings from 2014 to 2019, the most in-demand programming languages are SQL (appearing in 22% of all tech job postings) and Java (21%). Yet, SQL’s dominance is fading in recent years.

    根据Indeed.com从2014年至2019年的职位发布,最受欢迎的编程语言是SQL(在所有技术职位发布中占22%)和Java(21%)。 但是,近年来,SQL的统治地位正在减弱。

    If you are into mobile development, especially Android, you should learn Java over any other language. There are more than 2.3 billion mobile devices powered by Android. Since its foundation in the mid-90s, Java has always been topping the rankings.

    如果您喜欢移动开发,尤其是Android,则应该学习Java而不是其他任何语言。 有超过23亿部Android设备支持移动设备。 自90年代中期创立以来,Java一直位居榜首。

    Python (18%) takes the third place and is considered to continue its growth, mainly occupying data science jobs.

    Python(占18%)排在第三位,并被认为将继续增长,主要占据数据科学工作。

    It’s amazing how big Python has grown over the course of 5 years (2014–2019), from the 15th to the 3rd place. Python, along with C#, is considered to be one of the most profitable programming languages. If you are interested in AI, Machine Learning, or Data science, Python is the language you should learn.

    令人惊讶的是,Python在过去15年到第3位的5年间(2014-2019年)中发展壮大。 Python与C#一起被认为是最赚钱的编程语言之一。 如果您对AI,机器学习或数据科学感兴趣,那么Python是您应该学习的语言。

    With Python, you’ll be able to find a wide variety of programming jobs. Also, according to StackOverflow, Python has become the most wanted and useful programming language. And JavaScript takes second place as the most useful programming language. There are speculations that Python might become the most sought after programming language at some juncture.

    使用Python,您将能够找到各种各样的编程工作。 另外,根据StackOverflow的介绍,Python已成为最想要和最有用的编程语言。 JavaScript排在第二位,成为最有用的编程语言。 有人猜测,Python在某些时候可能会成为最受欢迎的编程语言。

    The fourth and fifth places are taken by Linux and JavaScript, respectively.

    第四和第五位分别是Linux和JavaScript。

    If you’re unsure about where to start with coding, learn JavaScript as it is the standard computer programming language of the web. Some people consider it to be “the best programming language to learn” as it helps you to get into computer programming rapidly. It’s used in a multitude of cases.

    如果不确定从哪里开始编码,请学习JavaScript,因为它是网络的标准计算机编程语言。 有些人认为它是“学习的最佳编程语言”,因为它可以帮助您快速进入计算机编程。 它用于多种情况。

    JavaScript makes websites interactive and compelling by adding dynamic styling, playful buttons, animations, and other interactive stuff.

    JavaScript通过添加动态样式,有趣的按钮,动画和其他交互式内容,使网站具有交互性和吸引力。

    Today, the web offers more than 1.5 billion websites and JavaScript is used in about 95% of them which makes the scope of it huge; you don’t have to worry about job opportunities when you know JavaScript.

    如今,Web提供了超过15亿个网站,其中约95%使用了JavaScript,这使它的范围变得很大。 当您了解JavaScript时,您不必担心工作机会。

    You can also use C# for building desktop applications and games. The language is suitable for web and mobile applications as well.

    您还可以使用C#构建桌面应用程序和游戏。 该语言也适用于Web和移动应用程序。

    34% of the most popular and free mobile games are made by developers coding on C#. The language was used to bring to life some of the most prominent mobile games of this century: Temple Run Trilogy and Assassin’s Creed Identity.

    34%的最受欢迎和免费的手机游戏由使用C#编码的开发人员制作。 该语言用于使本世纪一些最杰出的手机游戏栩栩如生:神庙逃亡三部曲和刺客信条:身份。

    C# is also quite user friendly. Errors can be identified easily because the code is checked by the framework before it’s deployed. C#, however, requires more time and practice to learn than, for example, Python.

    C#也非常用户友好。 可以轻松识别错误,因为在部署代码之前,框架会对其进行检查。 但是,C#比例如Python需要更多的时间和实践来学习。

    As an aside: You don’t necessarily need to have a computer science degree, a software developer certificate, or any other computer programming qualifications to get into programming. What you need is patience and hustle. You can be a self-taught programmer and still make it into FAANG (Facebook, Amazon, Apple, Netflix, Google), and command a high salary. Learning how to code is one of the best skills you can learn today. It’s worth it.

    顺便说一句:您不一定需要具备计算机科学学位,软件开发人员证书或任何其他计算机编程资格才能进行编程。 您需要的是耐心和奔忙。 您可以是一个自学成才的程序员,但仍然可以成为FAANG(Facebook,Amazon,Apple,Netflix,Google) ,并获得高薪。 学习如何编码是您今天可以学习的最佳技能之一。 这很值得。

    Coding is a good career regardless of the programming language you select (except if you decide to learn Brainfuck — the hardest programming language to learn).

    无论您选择哪种编程语言,编码都是一项不错的职业(除非您决定学习Brainfuck,这是最难学习的编程语言)。

    Coders can make somewhere from $80,000/yr to $500,000/yr and even more depending on their job title and the company they work for.

    编码人员的年收入从80,000美元到500,000美元不等,这取决于他们的职位和工作的公司。

    Programming is hard and that’s why you need to be curiously fascinated by it so you don’t perceive it as work but as pleasure. If you don’t plan on spending four years to get a CS degree, you can sign up for online computer programmer courses or take bootcamps.

    编程很辛苦,这就是为什么您需要对其着迷,所以您不会将其视为工作而是娱乐。 如果您不打算花费四年时间获得CS学位,则可以注册在线计算机程序员课程或参加训练营。

    YouTube频道可提高您的编程技能 (YouTube Channels To Enhance Your Programming Skills)

    YouTube is great for the what and the why, but text is the best for the how. Keep that in mind.

    YouTube擅长于“为什么”和“原因”,但文字最擅长“如何”。 记在脑子里。

    Some of the YouTube channels might be a bit obsolete. Nonetheless, the advice you’ll find will help you get into coding, land your first beginner programming job if you’re just starting out, or up your game significantly if you are a seasoned pro. All the listed channels below will help you advance your computer programming education.

    部分YouTube频道可能已过时。 尽管如此,您将找到的建议将帮助您进行编码,如果您只是刚开始,则可以从事初学者的编程工作,如果您是经验丰富的专业人士,则可以大大提高您的游戏水平。 下面列出的所有通道将帮助您推进计算机编程教育。

    So, in no particular order and without further ado:

    因此,没有特别的顺序,事不宜迟:

    遍历媒体 (Traversy Media)

    Image for post

    The number of tutorials this channel offers is enormous (it’s like a programming guide from A to Z). Many YouTubers who run similar programming channels say that the guy who owns Traversy Media influenced them in a way to start their own channel (one of those YouTubers is DevEd). On Traversy Media, you’ll find valuable sources on topics such as Angular, React, and Python. The quality of the content is impeccable. It’ll undoubtedly help you broaden your programming knowledge and enhance your computer programming skills.

    该频道提供的教程数量众多(就像从A到Z的编程指南一样)。 许多运行类似编程频道的YouTuber表示,拥有Traversy Media的家伙以某种方式影响了他们,以建立自己的频道( DevEd是其中一个YouTuber )。 在Traversy Media上,您会找到有关Angular,React和Python等主题的宝贵资源。 内容的质量是无可挑剔的。 无疑,它将帮助您拓宽编程知识并增强计算机编程技能。

    3蓝色1棕色 (3Blue1Brown)

    Image for post

    If you are a math person, 3Blue1Brown is the channel for you. It covers topics such as linear algebra, neural networks, calculus, topology, and more. Grant Sanderson, the channel owner, graduated from Stanford University in 2015 with a bachelor’s in math. When the lockdown happened because of the COVID-19 pandemic, he released a playlist of math tutorials named “Lockdown Math” to help students with studying from home. Grant has 3,07 million subscribers at the date of writing this article (10 September 2020). “The goal is for explanations to be driven by animations and for difficult problems to be made simple with changes in perspective.

    如果您是数学家,则3Blue1Brown是您的频道。 它涵盖了诸如线性代数,神经网络,微积分,拓扑等主题。 频道所有者格randint·桑德森(Grant Sanderson)于2015年毕业于斯坦福大学,并获得了数学学士学位。 当锁定因COVID-19大流行而发生时,他发布了名为“ Lockdown Math”的数学教程播放列表,以帮助学生在家中学习。 截至撰写本文之日(2020年9月10日),格randint拥有307万订户。 “目标是通过动画来推动解释,并通过改变视角来简化难题。

    素原 (ThePrimeagen)

    Image for post

    ThePrimeagen is great for Vim. It teaches mostly surface-level stuff. If you’re starting with Vim as your editor, this will be a great place to learn more. Here’s what other people say about the ThePrimeagen channel: “Youtube’s algorithm never failed me, I now shall worship it as a God, this channel changed my life.

    ThePrimeagen非常适合Vim。 它主要教授表面层的东西。 如果您以Vim作为编辑器,那么这将是学习更多的好地方。 这是其他人对ThePrimeagen频道的评价:“ Youtube的算法从未失败过我,我现在将其视为上帝,这个频道改变了我的生活。

    高拉夫森 (Gaurav Sen)

    Image for post

    Gaurav Sen focuses on digestible chunks of system design components. The guy teaches system design basics such as vertical and horizontal scaling and other system-related topics. Here’s what his subscribers have to say about him “OMG, you are just the system design guru I am looking for.

    Gaurav Sen专注于系统设计组件的可消化块。 这个家伙讲授系统设计基础知识,例如垂直和水平缩放以及其他与系统相关的主题。 这是他的订阅者必须对他说的“ OMG,您只是我正在寻找的系统设计专家。

    乔恩·詹塞特 (Jon Gjengset)

    Image for post

    When it comes to Rust, Jon Gjengset is the guy for you. He’s an open-source contributor to a variety of Rust projects. He’s also recording tons of Rust live coding streams, contributing to open source, and explaining his own projects all while teaching you Rust.

    关于Rust, Jon Gjengset是适合您的人。 他是Rust项目的各种开源贡献者。 他还录制了成千上万的Rust实时编码流,为开源做贡献,并在向您教授Rust的同时解释了自己的项目。

    两分钟论文 (Two Minute Papers)

    Image for post

    Two Minute Papers is a good channel for AI open projects. As the name suggests, you’ll also find 2-min videos of scientific papers. Many of the scientific papers revolve around graphics and neural networks. Go check it out if you are into machine learning, 3D printing, and AI.

    分钟论文是AI开放项目的好渠道。 顾名思义,您还会发现2分钟的科学论文视频。 许多科学论文都围绕图形和神经网络展开。 如果您喜欢机器学习,3D打印和AI,请检查一下。

    雷蒙德·海廷格(Raymond Hettinger) (Raymond Hettinger)

    {He doesn’t have a YouTube channel, but it’s enough to just type his name in the search bar to access his talks}

    {他没有YouTube频道,但只要在搜索栏中输入他的名字即可访问他的演讲}

    When it comes to the strength of Python, Raymond is one of the best guys to explain it to you. Here’s what some people say about him, “I am a simple man. I see Raymond Hettinger, I click like, play and save.” He teaches stuff like chunking and aliasing, building classes independently, graph traversal, libraries, and other stuff.

    当谈到Python的强大功能时,Raymond是向您解释它的最好的人之一。 这是一些关于他的话,“我是一个简单的人。 我看到Raymond Hettinger,我点击喜欢,播放并保存。 他教授诸如块和别名,独立地建立类,图形遍历,库之类的东西。

    简单程序员 (Simple Programmer)

    Image for post

    This channel is mainly geared towards junior programmers. Here, you’ll find general computer programming concepts so you can start coding almost right off the bat. John Sonmez, the owner of Simple Programmer, isn’t there to just teach you the coding basics; he also talks about life and gives excellent advice.

    该渠道主要面向初级程序员。 在这里,您将找到一般的计算机编程概念,因此几乎可以立即开始编码。 Simple Programmer的所有者John Sonmez不仅在这里教您编码基础知识; 他还谈到生活并提供出色的建议。

    编码火车 (The Coding Train)

    Image for post

    The channel is focused on coding for beginners. You’ll understand how to create simple games like Snake. Other videos include machine learning, simulation, JavaScript and more. His style of teaching is quite unique though, but not everybody may find it appealing. If you enjoy watching experienced developers making mistakes along the way and solving problems on the fly, then you will probably find this channel enjoyable.

    该频道侧重于为初学者编码。 您将了解如何创建诸如Snake之类的简单游戏。 其他视频包括机器学习,仿真,JavaScript等。 他的教学风格虽然很独特,但并不是每个人都可以吸引人。 如果您喜欢观看经验丰富的开发人员在执行过程中犯错并即时解决问题,那么您可能会发现此渠道很有趣。

    学术思想 (Academind)

    Image for post

    It’s great for JavaScript frameworks, CSS, and web development. It has tons of tutorials to help you get your foot in the door. The channel also offers in-depth 30-hours courses on topics such as JavaScript, Angular, Vue, Node.js and others.

    非常适合JavaScript框架,CSS和Web开发。 它包含大量的教程,可帮助您入门。 该频道还提供有关JavaScript,Angular,Vue,Node.js等主题的深入30小时课程。

    德里克·巴纳斯(Derek Banas) (Derek Banas)

    Image for post

    This guy covers anything related to computer programming. You’ll find hundreds of tutorials to help you out in your journey. Derek also created the widely-popular “Learn JavaScript in 30 Minutes” playlist. It consists of short videos packed with as much information as possible so you can hit the ground running rapidly.

    这个家伙涵盖了与计算机编程有关的所有内容。 您会发现数百本教程,可以在您的整个旅程中为您提供帮助。 Derek还创建了广受欢迎的“ 30分钟内学习JavaScript”播放列表。 它由简短的视频组成,其中包含尽可能多的信息,因此您可以Swift着手。

    马克·刘易斯 (Mark Lewis)

    Image for post

    Mark, a doctor and professor of Computer Science at Trinity University, offers a variety of videos focusing on the Scala framework (Scala is considered one of the best paying programming languages to learn). The channel also has tons of videos on general computer science for beginners and intermediates, functional programming, and more. With Mark, you’ll be able to expand your programming knowledge and improve your coding skills big time.

    Mark是三位一体大学的计算机科学专业的医生和教授,他提供了许多有关Scala框架的视频( Scala被认为是学习费用最高的编程语言之一)。 该频道还提供了许多有关初学者和中级,功能编程等的通用计算机科学视频。 使用Mark,您将能够扩展自己的编程知识并大量提高自己的编码技能。

    德·爱德 (Dev Ed)

    Image for post

    “I was watching this video on a 55” TV and my father entered exactly at 3:35. I’m still explaining to him that Ed is a programmer and this is a normal YouTube channel.” This guy has a unique personality that will keep you compelled while watching his videos. He discusses web dev, web design, 3d modeling, tools like Figma, and other exciting stuff. His content is mostly focused on coding for beginners.

    “我正在55英寸的电视上观看此视频,而父亲恰好是3:35进入 我仍在向他解释,埃德(Ed)是一名程序员,这是正常的YouTube频道。 ”这个人具有独特的个性,可以让您在观看他的视频时被强迫。 他讨论了Web开发,Web设计,3D建模,Figma之类的工具以及其他令人兴奋的内容。 他的内容主要集中于为初学者编写代码。

    网络忍者 (The Net Ninja)

    Image for post

    Net Ninja’s videos are some of the best videos on programming out there. You’ll find videos on topics such as JavaScript (beginner to advanced coding), Node.js, React, Vue.js, Firebase, MongoDB, HTML, and CSS. The guy who runs the channels is a skillful developer and all of his content is free. You can pay for Udemy courses, watch them, and still won’t find as much value as you’d by watching Net Ninja’s free videos. As a matter of fact, some of the Udemy courses borrow materials from Net Ninja and teach his stuff in their paid courses. This channel is like a mini computer programming education school that can significantly improve your coding skills.

    Net Ninja的视频是那里最好的一些编程视频。 您会找到有关诸如JavaScript(从入门到高级编码),Node.js,React,Vue.js,Firebase,MongoDB,HTML和CSS等主题的视频。 运行频道的人是一个熟练的开发人员,他的所有内容都是免费的。 您可以为Udemy课程付费,观看它们,但仍然无法像观看Net Ninja的免费视频那样找到最大的价值。 实际上,一些Udemy课程从Net Ninja借用了资料,并在其付费课程中教授了他的东西。 该频道就像一台小型计算机编程教育学校,可以极大地提高您的编码技能。

    趣味功能 (Fun Fun Function)

    Image for post

    Unfortunately, Mattias, the channel owner, stopped shooting videos 2 months ago but didn’t completely close the doors to his channel. He didn’t tell, however, for how long he’ll be taking a break, so years might pass until we hear from him again. Nevertheless, his videos offer great programming tips. His quirkiness will always keep you entertained. It’s one of the best channels for mastering JavaScript. Mattias brings a variety of videos to the table discussing functional programming, object creation, iterators and generators, and other JS features.

    不幸的是,频道所有者Mattias于2个月前停止拍摄视频,但并未完全关闭频道。 但是,他没有告诉他要休息多久,所以几年可能会过去,直到我们再次听到他的消息。 不过,他的视频提供了很棒的编程技巧。 他的古怪将使您始终保持娱乐。 这是掌握JavaScript的最佳渠道之一。 Mattias带来了很多视频,讨论功能编程,对象创建,迭代器和生成器以及其他JS功能。

    电脑爱好者 (Computerphile)

    Image for post

    Computerphile is a great channel, but it’s mainly targeted towards junior developers or soon-to-be developers. The owner of the channel is Brady Haran who simultaneously runs other channels such as Numberphile (focused on mathematics), Sixty Symbols (based around physics), Periodic Videos (chemistry), and Deep Sky Videos (centered around astronomy). His passion for computers is definitely infectious; you’ll find yourself compelled by his videos as soon as you hit the “Play” button. His videos cover topics such as blockchain, bitcoin, game computer coding, automatic, code testing and more.

    Computerphile是一个不错的渠道,但主要针对初级开发人员或即将成为开发人员的人员。 该频道的所有者是布雷迪·哈兰(Brady Haran),他同时运营其他频道,例如Numberphile(专注于数学),60符号(基于物理学),定期视频(化学)和Deep Sky视频(围绕天文学)。 他对计算机的热情绝对具有感染力。 按下“播放”按钮后,您会发现自己被他的视频所吸引。 他的视频涵盖了诸如区块链,比特币,游戏计算机编码,自动,代码测试等主题。

    比斯威特 (Bisqwit)

    Image for post

    I find this one compelling because of the guy’s quirky accent (mean it in a good way). By following this channel you’ll learn about C++, emulators, and other cool programming stuff. You should check it out if you love the art of programming.

    我觉得这很引人注目,是因为这个家伙的古怪的口音(很好的意思)。 通过关注该频道,您将了解C ++,仿真器和其他出色的编程知识。 如果您喜欢编程艺术,就应该检查一下。

    薄矩阵 (ThinMatrix)

    Image for post

    If you are interested in creating your own 3D game engine using OpenGL, the ThinMatrix channel offers more than 50 tutorial videos to help you out with that. Karl, the guy who runs the channel, is an indie game developer who has been developing games full-time for more than 5 years. What’s cool about his channel is that he documents his progress as an indie developer and shares great programming tips & tricks. In 2018, Karl released his own game called “Equilinox.”

    如果您有兴趣使用OpenGL创建自己的3D游戏引擎,ThinMatrix频道提供了50多个教程视频来帮助您解决问题。 负责频道运营的Karl是一位独立游戏开发商,他从事全职游戏开发已有5年以上。 他的频道最酷的地方是,他记录了自己作为独立开发人员的进度,并分享了很棒的编程技巧和窍门。 在2018年,卡尔发布了自己的游戏“ Equilinox”。

    销毁所有软件的Gary (Gary of Destroy All of Software)

    Image for post

    Although this is not a YouTube channel and requires a monthly subscription of $29/mo, Gary offers both beginners and advanced developers videos. The content is mainly focused on helping you to learn computer science.

    尽管这不是YouTube频道,并且需要每月29美元/月的订阅费,但Gary既提供初学者又提供高级开发者视频。 内容主要侧重于帮助您学习计算机科学。

    帕特里克·JMT (PatrickJMT)

    Image for post

    If you are trying to get into the nitty-gritty of math, the PatrickJMT channel can definitely help you out in your journey. The channel is considered to be an invaluable resource of math-related topics. Whether you are a beginner coder or an advanced one, Patrick will help you grasp basic math concepts and up your math game. You’ll learn more about trigonometry, derivatives, antiderivatives, integrals, linear algebra, and more. Another option is Khan Academy.

    如果您想深入了解数学, PatrickJMT频道绝对可以为您提供帮助。 该频道被认为是与数学相关的主题的宝贵资源。 无论您是初学者还是高级编码员,Patrick都会帮助您掌握基本的数学概念并提高您的数学游戏水平。 您将了解有关三角函数,导数,反导数,积分,线性代数等的更多信息。 另一个选择是可汗学院

    本·阿瓦德 (Ben Awad)

    Image for post

    Ben Awad’s channel on YouTube offers great general programming content. He posts videos like “programming memes,” “Programming Best practices,’” “Coding interviews are broken” so you can unwind after learning a new sophisticated concept.

    Ben Awad在YouTube上频道提供了精彩的常规节目内容。 他发布了“编程模因”,“编程最佳实践”,“编码面试被打断”之类的视频,这样您就可以在学习新的复杂概念后放松身心。

    Google Chrome开发人员 (Google Chrome Developers)

    Image for post

    With Google Chrome Developers, you can learn about fundamental issues such as browser APIs and web components. It covers topics suitable for both beginners and advanced. You’ll learn the fundamentals of coding in no time.

    借助Google Chrome开发人员,您可以了解一些基本问题,例如浏览器API和网络组件。 它涵盖了适合初学者和高级人士的主题。 您将立即学习编码的基础知识。

    结论 (Conclusion)

    So there you have them. The best YouTube chance to improve your programming skills and coding career.

    所以那里有他们。 YouTube改善您的编程技能和编码职业的最佳机会。

    Of course, there’s an infinite number of other amazing channels out there. Let me know in the comments which one is your favorite and I’ll make sure to include it whenever I update this article.

    当然,还有无数其他惊人的渠道。 在评论中让我知道您最喜欢哪一个,并且在更新本文时,请确保将其包括在内。

    Stay unparalleled,

    保持无与伦比,

    P.S. It’d be sinful not to make a short blurb about Codegiant in a Codegiant article. I decided to save it for the last because I also hate it when I’m reading other articles peppered with a myriad of ads about their tools throughout.

    PS:在Codegiant文章中不对Codegiant进行简短介绍是有罪的。 我决定将其保存为最后一个版本,因为当我阅读其他文章时,也讨厌它,因为有关它们的工具的广告不胜枚举。

    So, if you are searching for a GitHub/GitLab alternative that offers a simply-designed issue tracker, git repositories, built-in CI/CD, and documentation tool, then feel free to check out Codegiant. That’s it. Enjoy!

    因此,如果您正在寻找提供简单设计的问题跟踪器,git仓库,内置CI / CD和文档工具的GitHub / GitLab替代方案,请随时查看Codegiant 。 而已。 请享用!

    翻译自: https://blog.codegiant.io/programming-skills-d77d4abdf255

    单片机编程技巧

    展开全文
  • 单片机编程技巧-功能强大的时钟中断 功能强大的时钟中断 在单片机程序设计中,设置一个好的时钟中断,将能使一个CPU发挥两个CPU的功效,大大方便和简化程序。
  • 单片机编程技巧100例.pdf
  • 单片机编程技巧总结

    2021-01-25 21:29:21
    单片机编程技巧总结 1.

    **

    一.关于按键的操作

    **
    1.“异或”识别

    通过使用“异或”的一个if判断,很完美的检测到每一次的按键变化

    2.状态机的使用

    展开全文
  • 单片机编程技巧100问

    2011-11-17 12:08:59
    全面的单片机编程技巧,问答结合,助你更好的理解单片机编程。
  • EMC单片机编程技巧集锦,是 pdf 文件,希望对大家有帮助!
  • 1.C语言和汇编语言在开发单片机时各有哪些优缺点? 答:汇编语言是一种用文字助记符来表示机器指令的符号语言,是最接近机器码的一种语言。其主要优点是占用资源少、程序执行效率高。但是不同的CPU,其汇编语言可能...
  • 摘要:不知道大家有没有这样一种感觉,就是感觉自己玩单片机还可以,各个功能模块也都会驱动,但是如果让你完整的写一套代码,却无逻辑与框架可言,上来就是开始写!东抄抄写抄抄。说明编程还处于比较低...

    摘要:不知道大家有没有这样一种感觉,就是感觉自己玩单片机还可以,各个功能模块也都会驱动,但是如果让你完整的写一套代码,却无逻辑与框架可言,上来就是开始写!东抄抄写抄抄。说明编程还处于比较低的水平,那么如何才能提高自己的编程水平呢?学会一种好的编程框架或者一种编程思想,可能会受用终生!比如模块化编程,框架式编程,状态机编程等等,都是一种好的框架。

    今天说的就是状态机编程,由于篇幅较长,大家慢慢欣赏。那么状态机是一个这样的东东?状态机(state machine)有5个要素,分别是状态(state)、迁移(transition)、事件(event)、动作(action)、条件(guard)。

    什么是状态机?

    状态机是一个这样的东东:状态机(state machine)有 5 个要素,分别是状态(state)、迁移(transition)、事件(event)、动作(action)、条件(guard)。

    状态:一个系统在某一时刻所存在的稳定的工作情况,系统在整个工作周期中可能有多个状态。例如一部电动机共有正转、反转、停转这 3 种状态。

    一个状态机需要在状态集合中选取一个状态作为初始状态。

    迁移:系统从一个状态转移到另一个状态的过程称作迁移,迁移不是自动发生的,需要外界对系统施加影响。停转的电动机自己不会转起来,让它转起来必须上电。

    事件:某一时刻发生的对系统有意义的事情,状态机之所以发生状态迁移,就是因为出现了事件。对电动机来讲,加正电压、加负电压、断电就是事件

    动作:在状态机的迁移过程中,状态机会做出一些其它的行为,这些行为就是动作,动作是状态机对事件的响应。给停转的电动机加正电压,电动机由停转状态迁移到正转状态,同时会启动电机,这个启动过程可以看做是动作,也就是对上电事件的响应。

    条件:状态机对事件并不是有求必应的,有了事件,状态机还要满足一定的条件才能发生状态迁移。还是以停转状态的电动机为例,虽然合闸上电了,但是如果供电线路有问题的话,电动机还是不能转起来。

    只谈概念太空洞了,上一个小例子:一单片机、一按键、俩 LED 灯(记为L1和L2)、一人, 足矣!

    规则描述:

    1、L1L2状态转换顺序OFF/OFF--->ON/OFF--->ON/ON--->OFF/ON--->OFF/OFF

    2、通过按键控制L1L2的状态,每次状态转换需连续按键5

    3、L1L2的初始状态OFF/OFF

    图1

    下面这段程序是根据功能要求写成的代码。

    程序清单List1:

    void main(void)
    {
     sys_init();
     led_off(LED1);
     led_off(LED2);
     g_stFSM.u8LedStat = LS_OFFOFF;
     g_stFSM.u8KeyCnt = 0;
     while(1)
     {
      if(test_key()==TRUE)
      {
       fsm_active();
      }
      else
      {
       ; /*idle code*/
      }
     }
    }
    void fsm_active(void)
    {
     if(g_stFSM.u8KeyCnt > 3) /*击键是否满 5 次*/
     {
      switch(g_stFSM.u8LedStat)
      {
       case LS_OFFOFF:
        led_on(LED1); /*输出动作*/
        g_stFSM.u8KeyCnt = 0;
        g_stFSM.u8LedStat = LS_ONOFF; /*状态迁移*/
        break;
       case LS_ONOFF:
        led_on(LED2); /*输出动作*/
        g_stFSM.u8KeyCnt = 0;
        g_stFSM.u8LedStat = LS_ONON; /*状态迁移*/
        break;
       case LS_ONON:
        led_off(LED1); /*输出动作*/
        g_stFSM.u8KeyCnt = 0;
        g_stFSM.u8LedStat = LS_OFFON; /*状态迁移*/
        break;
       case LS_OFFON:
        led_off(LED2); /*输出动作*/
        g_stFSM.u8KeyCnt = 0;
        g_stFSM.u8LedStat = LS_OFFOFF; /*状态迁移*/
        break;
       default: /*非法状态*/
        led_off(LED1);
        led_off(LED2);
        g_stFSM.u8KeyCnt = 0;
        g_stFSM.u8LedStat = LS_OFFOFF; /*恢复初始状态*/
        break;
      }
     }
     else
     {
      g_stFSM.u8KeyCnt++; /*状态不迁移,仅记录击键次数*/
     }
    }
    

    实际上在状态机编程中,正确的顺序应该是先有状态转换图,后有程序,程序应该是根据设计好的状态图写出来的。不过考虑到有些童鞋会觉得代码要比转换图来得亲切,我就先把程序放在前头了。

    这张状态转换图是用UML(统一建模语言)的语法元素画出来的,语法不是很标准,但拿来解释问题足够了。

    图2按键控制流水灯状态转换图

    圆角矩形代表状态机的各个状态,里面标注着状态的名称。

    带箭头的直线或弧线代表状态迁移,起于初态,止于次态。

    图中的文字内容是对迁移的说明,格式是:事件[条件]/动作列表(后两项可选)。

    “事件[条件]/动作列表”要说明的意思是:如果在某个状态下发生了“事件”,并且状态机

    满足“[条件]”,那么就要执行此次状态转移,同时要产生一系列“动作”,以响应事件。在这个例子里,我用“KEY”表示击键事件。

    图中有一个黑色实心圆点,表示状态机在工作之前所处的一种不可知的状态,在运行之前状态机必须强制地由这个状态迁移到初始状态,这个迁移可以有动作列表(如图1所示),但不需要事件触发。

    图中还有一个包含黑色实心圆点的圆圈,表示状态机生命周期的结束,这个例子中的状态机生生不息,所以没有状态指向该圆圈。

    关于这个状态转换图就不多说了,相信大家结合着上面的代码能很容易看明白。现在我们再聊一聊程序清单List1。

    先看一下fsm_active()这个函数,g_stFSM.u8KeyCnt = 0;这个语句在switch—case里共出现了 5 次,前 4 次是作为各个状态迁移的动作出现的。从代码简化提高效率的角度来看,我们完全可以把这 5 次合并为 1 次放在 switch—case 语句之前,两者的效果是完全一样的,代码里之所以这样啰嗦,是为了清晰地表明每次状态迁移中所有的动作细节,这种方式和图2的状态转换图所要表达的意图是完全一致的。

    再看一下g_stFSM这个状态机结构体变量,它有两个成员:u8LedStatu8KeyCnt。用这个结构体来做状态机好像有点儿啰嗦,我们能不能只用一个像 u8LedStat 这样的整型变量来做状态机呢?

    当然可以!我们把图 2中的这 4 个状态各自拆分成 5 个小状态,这样用 20 个状态同样能实现这个状态机,而且只需要一个 unsigned char 型的变量就足够了,每次击键都会引发状态迁移, 每迁移 5 次就能改变一次 LED 灯的状态,从外面看两种方法的效果完全一样。

    假设我把功能要求改一下,把连续击键5次改变L1L2的状态改为连续击键100次才能改变L1L2的状态。这样的话第二种方法需要4X100=400个状态!而且函数fsm_active()中的switch—case语句里要有400个case,这样的程序还有法儿写么?!

    同样的功能改动,如果用g_stFSM这个结构体来实现状态机的话,函数fsm_active()只需要将if(g_stFSM.u8KeyCnt>3)改为if(g_stFSM.u8KeyCnt > 98)就可以了!

    g_stFSM结构体的两个成员中,u8LedStat可以看作是质变因子,相当于主变量;u8KeyCnt可以看作是量变因子,相当于辅助变量。量变因子的逐步积累会引发质变因子的变化。

    g_stFSM这样的状态机被称作Extended State Machine,我不知道业内正规的中文术语怎么讲,只好把英文词组搬过来了。

    2、状态机编程的优点

    说了这么多,大家大概明白状态机到底是个什么东西了,也知道状态机化的程序大体怎么写了,那么单片机的程序用状态机的方法来写有什么好处呢?

    (1)提高CPU使用效率

    话说我只要见到满篇都是delay_ms()的程序就会蛋疼,动辄十几个ms几十个ms的软件延时是对CPU资源的巨大浪费,宝贵的CPU机时都浪费在了NOP指令上。那种为了等待一个管脚电平跳变或者一个串口数据而岿然不动的程序也让我非常纠结,如果事件一直不发生,你要等到世界末日么?

    把程序状态机化,这种情况就会明显改观,程序只需要用全局变量记录下工作状态,就可以转头去干别的工作了,当然忙完那些活儿之后要再看看工作状态有没有变化。只要目标事件(定时未到、电平没跳变、串口数据没收完)还没发生,工作状态就不会改变,程序就一直重复着“查询—干别的—查询—干别的”这样的循环,这样CPU就闲不下来了。在程序清单 List3 中,if{}else{}语句里else下的内容(代码中没有添加,只是加了一条/*idle code*/的注释示意)就是上文所说的“别的工作” 。

    这种处理方法的实质就是在程序等待事件的过程中间隔性地插入一些有意义的工作,好让CPU不是一直无谓地等待。

    (2) 逻辑完备性

    我觉得逻辑完备性是状态机编程最大的优点

    不知道大家有没有用C语言写过计算器的小程序,我很早以前写过,写出来一测试,那个惨不忍睹啊!当我规规矩矩的输入算式的时候,程序可以得到正确的计算结果,但要是故意输入数字和运算符号的随意组合,程序总是得出莫名其妙的结果。

    后来我试着思维模拟一下程序的工作过程,正确的算式思路清晰,流程顺畅,可要碰上了不规矩的式子,走着走着我就晕菜了,那么多的标志位,那么多的变量,变来变去,最后直接分析不下去了。

    很久之后我认识了状态机,才恍然明白,当时的程序是有逻辑漏洞的。如果把这个计算器程序当做是一个反应式系统,那么一个数字或者运算符就可以看做一个事件,一个算式就是一组事件组合。对于一个逻辑完备的反应式系统,不管什么样的事件组合,系统都能正确处理事件,而且系统自身的工作状态也一直处在可知可控的状态中。反过来,如果一个系统的逻辑功能不完备,在某些特定事件组合的驱动下,系统就会进入一个不可知不可控的状态,与设计者的意图相悖。

    状态机就能解决逻辑完备性的问题。

    状态机是一种以系统状态为中心,以事件为变量的设计方法,它专注于各个状态的特点以及状态之间相互转换的关系。状态的转换恰恰是事件引起的,那么在研究某个具体状态的时候,我们自然而然地会考虑任何一个事件对这个状态有什么样的影响。这样,每一个状态中发生的每一个事件都会在我们的考虑之中,也就不会留下逻辑漏洞。

    这样说也许大家会觉得太空洞,实践出真知,某天如果你真的要设计一个逻辑复杂的程序,

    我保证你会说:哇!状态机真的很好用哎!

    (3)程序结构清晰

    用状态机写出来的程序的结构是非常清晰的。

    程序员最痛苦的事儿莫过于读别人写的代码。如果代码不是很规范,而且手里还没有流程图,读代码会让人晕了又晕,只有顺着程序一遍又一遍的看,很多遍之后才能隐约地明白程序大体的工作过程。有流程图会好一点,但是如果程序比较大,流程图也不会画得多详细,很多细节上的过程还是要从代码中理解。

    相比之下,用状态机写的程序要好很多,拿一张标准的UML状态转换图,再配上一些简明的文字说明,程序中的各个要素一览无余。程序中有哪些状态,会发生哪些事件,状态机如何响应,响应之后跳转到哪个状态,这些都十分明朗,甚至许多动作细节都能从状态转换图中找到。可以毫不夸张的说,有了UML状态转换图,程序流程图写都不用写。

    套用一句广告词:谁用谁知道!

    果子哥制作

    说明:文章转载自一篇pdf文档,作者Alicedodo,旨在分享技术知识,如有侵权请联系删除!


    推荐阅读:

    专辑|Linux文章汇总

    专辑|程序人生

    专辑|C语言

    我的知识小密圈

    关注公众号,后台回复「1024」获取学习资料网盘链接。

    欢迎点赞,关注,转发,在看,您的每一次鼓励,我都将铭记于心~

    嵌入式Linux

    微信扫描二维码,关注我的公众号

    展开全文
  • 先说明一下,我下面要说的LCD1602的芯片驱动是HD44780,如果你们的LCD1602驱动芯片不是HD44780,那么下面的内容是不适用的。
  • 单片机编程技巧与实例,C51程序基本语法。
  • 单片机程序设计中,设置一个好的时钟中断,将能使一个CPU发挥两个CPU的功效,大大方便和简化程序的编制,提高系统的效率与可操作性。我们可以把一些例行的及需要定时执行的程序放在时钟中断中,还可以利用时钟中断...
  • 单片机编程技巧95问

    2012-03-11 18:01:12
    资源详细介绍C语言和汇编语言在开发单片机的优缺点,以及应用注意事项,整理成文档供大家学习。
  • 飞思卡尔智能汽车大赛指定芯片MC9S12单片机编程技巧大全
  • 单片机程序设计中,设置一个好的时钟中断,将能使一个CPU发挥两个CPU的功效,大大方便和简化程序的编制,提高系统的效率与可操作性。我们可以把一些例行的及需要定时执行的程序放在时钟中断中,还可以利用时钟中断...
  • 分析和讲述了单片机编程过程中要注意的一系列事项,对编程方法做了分析,是一份ppt的文档。
  • 1. C语言和汇编语言在开发单片机时各有哪些优缺点?3. 搞单片机开发,一定要会C吗?
  • 对寄存器的分配、程序页面的布局有很详细的介绍。很实用
  • f 一学就会的单片机编程技巧与实例_14011139[General Information]书名=一学就会的单片机编程技巧与实例作者=刘桂兰,刘理云编页数=205SS号DX号=出版日期=2016.09出版社=化学工业出版社封面书名版权前言目录第1章 ...

    f 一学就会的单片机编程技巧与实例_14011139

    [General Information]

    书名=一学就会的单片机编程技巧与实例

    作者=刘桂兰,刘理云编

    页数=205

    SS号

    DX号=

    出版日期=2016.09

    出版社=化学工业出版社

    封面

    书名

    版权

    前言

    目录

    第1章 单片机硬件基础

    1.1 单片机的发展及分类

    1.1.1 单片机的发展

    1.1.2 单片机的分类

    1.2 单片机的外部结构及引脚

    1.3 单片机的内部结构及组成

    1.4 单片机的最小系统

    1.4.1 CPU时序及时钟电路

    1.4.2 复位电路

    第2章 汇编语言编程基础

    2.1 MCS-51单片机指令系统

    2.1.1 指令系统

    2.1.2 寻址方式

    2.1.3 MCS-51指令系统

    2.2 汇编语言程序设计初步

    2.2.1 程序流程图

    2.2.2 程序结构与设计举例

    第3章 用汇编语言编程的单片机应用实例

    3.1 汇编语言基础型应用实例

    3.1.1 单片机控制发光二极管点亮及闪烁

    3.1.2 单片机控制发光二极管循环点亮及跑动

    3.1.3 独立键盘键控发光二极管工作

    3.1.4 单片机控制一位数码管显示

    3.1.5 单片机控制多位数码管显示

    3.1.6 单片机控制步进电动机运转

    3.1.7 单片机控制直流电动机运转

    3.1.8 单片机控制简易交通灯

    3.1.9 火灾报警器

    3.1.10 单片机帮我测心跳

    3.2 综合型应用实例

    3.2.1 单片机控制音乐播放器

    3.2.2 数字秒表

    3.2.3 单片机控制洗衣机

    3.2.4 单片机控制酒精测试仪

    3.2.5 单片机控制水塔水位

    3.2.6 单片机控制运料小车

    3.2.7 单片机控制密码电路

    3.2.8 D/A转换驱动小直流电动机

    3.2.9 直冷式电冰箱单片机控制系统

    3.2.10 剪切机的单片机控制系统

    第4章 C51程序编程基础

    4.1 C51程序的基本组成

    4.2 C51的数据结构

    4.2.1 C51的数据类型

    4.2.2 C51的常量

    4.2.3 C51的变量及存储器类型

    4.3 C51的运算符

    4.3.1 赋值运算符

    4.3.2 算术运算符

    4.3.3 关系运算符

    4.3.4 逻辑运算符

    4.3.5 位运算符

    4.3.6 复合赋值运算符

    4.3.7 逗号运算符

    4.3.8 条件运算符

    4.3

    展开全文
  • 编程技巧
  • 前言 为什么要写自己库呢? 因为随着项目的越来越复杂,如果代码都堆再一个main.c文件里的话管理起来会比较难。你出现想找到某部分的代码得上下翻找。...如果需要用的单片机的资源要包含它的头文件,不然

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 4,628
精华内容 1,851
关键字:

单片机编程技巧