unsigned

秒表计时器

不打扰是莪最后的温柔 提交于 2019-12-04 01:54:14
秒表计时器 制作一个秒表计时器,记录0-15秒时间。要求精准,可控。 1.能够用按键控制秒表开始 2.能够用按键控制秒表停止 3.能够用按键控制秒表清零 4.使用定时器控制时间,要求精确。 5.使用1个数码管和多个按键实现功能。 代码如下: #include<reg52.h> #define LED P0 sbit KEY1 = P1^0; sbit KEY2 = P1^1; unsigned int i = 0; unsigned char LED_NUM[] = {0xc0,0xf9,0xa4,0xb0,\ 0x99,0x92,0x82,0xf8,\ 0x80,0x90,0x88,0x83,\ 0xc6,0xa1,0x86,0x8e}; unsigned char n = 0; void INT_T0(void) { TMOD = 0X01; //打开定时器0 ,使用模式1定时 TH0 = 0XFC; TL0 = 0X18; //初始值 EA = 1;//打开总开关 ET0 = 1;//打开中断T0开关 } void main(void) { INT_T0(); TR0 = 0; //定时功能打开 while(1) { if(KEY1==0) { TR0 = 1; } if(KEY2==1) { i = 0; n = 0; } } } void time0(void)

【原创】(十)Linux内存管理 - zoned page frame allocator - 5

帅比萌擦擦* 提交于 2019-12-04 01:36:23
背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: Kernel版本:4.14 ARM64处理器,Contex-A53,双核 使用工具:Source Insight 3.5, Visio 1. 概述 本文将讨论 memory reclaim 内存回收这个话题。 在内存分配出现不足时,可以通过唤醒 kswapd 内核线程来异步回收,或者通过 direct reclaim 直接回收来处理。在针对不同的物理页会采取相应的回收策略,而页回收算法采用 LRU(Least Recently Used) 来选择物理页。 直奔主题吧。 2. LRU和pagevec 2.1 数据结构 简单来说,每个 Node 节点会维护一个 lrvvec 结构,该结构用于存放5种不同类型的 LRU链表 ,在内存进行回收时,在 LRU链表 中检索最少使用的页面进行处理。 为了提高性能,每个CPU有5个 struct pagevecs 结构,存储一定数量的页面(14),最终一次性把这些页面加入到 LRU链表 中。 上述的描述不太直观,先看代码,后看图,一目了然! typedef struct pglist_data { ... /* Fields commonly accessed by

The importance of declaring a variable as unsigned

有些话、适合烂在心里 提交于 2019-12-04 01:17:06
Is it important to declare a variable as unsigned if you know it should never be negative? Does it help prevent anything other than negative numbers being fed into a function that shouldn't have them? Declaring variables for semantically non-negative values as unsigned is a good style and good programming practice. However, keep in mind that it doesn't prevent you from making errors. If is perfectly legal to assign negative values to unsigned integers, with the value getting implicitly converted to unsigned form in accordance with the rules of unsigned arithmetic. Some compilers might issue

秒表计时器

南楼画角 提交于 2019-12-04 01:02:39
秒表计时器 制作一个秒表计时器,记录0-15秒时间。要求精准,可控。 1.能够用按键控制秒表开始 2.能够用按键控制秒表停止 3.能够用按键控制秒表清零 4.使用定时器控制时间,要求精确。 5.使用1个数码管和多个按键实现功能。 代码如下: #include<reg52.h> #define LED P0 sbit KEY1 = P1^0; sbit KEY2 = P1^1; unsigned int i = 0; unsigned char LED_NUM[] = {0xc0,0xf9,0xa4,0xb0,\ 0x99,0x92,0x82,0xf8,\ 0x80,0x90,0x88,0x83,\ 0xc6,0xa1,0x86,0x8e}; unsigned char n = 0; void INT_T0(void) { TMOD = 0X01; //打开定时器0 ,使用模式1定时 TH0 = 0XFC; TL0 = 0X18; //初始值 EA = 1;//打开总开关 ET0 = 1;//打开中断T0开关 } void main(void) { INT_T0(); TR0 = 0; //定时功能打开 while(1) { if(KEY1==0) { TR0 = 1; } if(KEY2==1) { i = 0; n = 0; } } } void time0(void)

acceptable fix for majority of signed/unsigned warnings?

烂漫一生 提交于 2019-12-04 00:32:01
问题 I myself am convinced that in a project I'm working on signed integers are the best choice in the majority of cases, even though the value contained within can never be negative. (Simpler reverse for loops, less chance for bugs, etc., in particular for integers which can only hold values between 0 and, say, 20, anyway.) The majority of the places where this goes wrong is a simple iteration of a std::vector, often this used to be an array in the past and has been changed to a std::vector later

Why is uint_least16_t faster than uint_fast16_t for multiplication in x86_64?

↘锁芯ラ 提交于 2019-12-04 00:10:24
问题 The C standard is quite unclear about the uint_fast*_t family of types. On a gcc-4.4.4 linux x86_64 system, the types uint_fast16_t and uint_fast32_t are both 8 bytes in size. However, multiplication of 8-byte numbers seems to be fairly slower than multiplication of 4-byte numbers. The following piece of code demonstrates that: #include <stdio.h> #include <stdint.h> #include <inttypes.h> int main () { uint_least16_t p, x; int count; p = 1; for (count = 100000; count != 0; --count) for (x = 1;

利用一个数码管和两个开关实现秒表0-9功能

时间秒杀一切 提交于 2019-12-03 23:34:07
#include<reg52.h> #define LED_ALL P0 sbit LED = P0^0; sbit key1 = P1^0; sbit key2 = P1^1; unsigned int i = 0; unsigned n = 0; unsigned char num[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff}; void INT_T0(void) { TMOD = 0X01; //打开定时器0 ,使用模式1定时 TH0 = 0XFC; TL0 = 0X18; //初始值 EA = 1;//打开总开关 ET0 = 1;//打开中断T0开关 } void main(void) { INT_T0(); TR0 = 1; //定时功能打开 while(1) { if(key1==0) TR0 = 1; else TR0 = 0; if(key2==0) n=0; LED_ALL=num[n]; } } void time0(void) interrupt 1 { TH0 = 0XFC; TL0 = 0X18; //初始值 if(i < 1000) { i++; } else { P0 = num[n]; i = 0; if(n<9) n++; else n=0; } } 来源: https:/

秒表计时器

£可爱£侵袭症+ 提交于 2019-12-03 23:24:40
制作一个秒表计时器,记录0-15秒时间。要求精准,可控。 1.能够用按键控制秒表开始 2.能够用按键控制秒表停止 3.能够用按键控制秒表清零 4.使用定时器控制时间,要求精确。 5.使用1个数码管和多个按键实现功能。 先根据需求判断所需的功能,再改变电路图 然后根据要求开始写代码 1 #include<reg52.h> 2 sbit an = P1^0; 3 sbit qing = P1^1; 4 unsigned int i = 0; 5 unsigned int s = 0; 6 code unsigned char LED_CODE[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xA7,0xA1,0x86,0x8E}; 7 void INT_T0(void) 8 { 9 TMOD = 0X01; //打开定时器0 ,使用模式1定时 10 TH0 = 0XFC; 11 TL0 = 0X18; //初始值 12 EA = 1;//打开总开关 13 ET0 = 1;//打开中断T0开关 14 } 15 void main(void) 16 { 17 INT_T0(); 18 TR0 = 0; //定时功能关闭 19 while(1) 20 { 21 if(an == 0) 22 TR0 = 1;

Why Is Comparing if an Unsigned Int >= 0 a “Pointless Comparison”?

这一生的挚爱 提交于 2019-12-03 22:35:15
I got warning: Pe186 "Pointless comparison of unsigned int with zero" when I tried to compile the following code: for(clLoop = cpLoopStart; clLoop >= 0; clLoop--) { //Do something } I don't understand why. I could understand, if I were looking for a value less than zero, since an unsigned int can never be negative. But all I am looking for here is if it is equal to zero, which an unsigned int certainly can be. I could even see this error if in this loop I tried to pre-decrement instead of post-decrement, but again that is not the case. You check whether the unsigned int is greater than or

Signed vs Unsigned operations in C

北城以北 提交于 2019-12-03 17:45:45
问题 Very simple question: I have a program doing lots and lots of mathematical computations over ints and long longs. To fit in an extra bit, I made the long longs unsigned, since I only dealt with positive numbers, and could now get a few more values. Oddly enough, this gave me a 15% performance boost, which I confirmed to be in simply making all the long long's unsigned. Is this possible? Are mathematical operations really faster with unsigned numbers? I remember reading that there would be no