两数之和c语言刷题123

5回复/ 0534 浏览
c语言考试刷题(1级)楼主2024-06-27 22:08:28发布于山东
两数之和c语言刷题123c语言考试刷题 发表在步行街主干道 https://bbs.hupu.com/topic-daily

全部回帖

收起

别被转水

别被转水

亮了(0)
回复

//头文件2222
#include
#include "intrins.h"
unsigned int count = 1994;

void Delay1ms();
void DelayNms(unsigned int t);

//unsigned char code SEG_Table[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x671};//显示0~F的值 共阴极
//0~F段码 //显示0~F的值 共阴极

unsigned char code SEG_Table[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//显示0~F的值 共阳极
//0~F段码 //显示0~F的值 共阳极

void int0_init()
{
EA = 1;
IT0 = 1;
EX0 = 1;
}
void int0_serve() interrupt 0
{
count++;
if(count >= 2000)
{
count = 0;
}
}

void main()
{
int0_init();
while(1)
{
//按键计数
P2 = SEG_Table[count/1000];
P1 = 0x01;
DelayNms(2);
P2 = 0xff;

P2 = SEG_Table[(count%1000)/100];
P1 = 0x02;
DelayNms(2);
P2 = 0xff;

P2 = SEG_Table[(count%100)/10];
P1 = 0x04;
DelayNms(2);
P2 = 0xff;

P2 = SEG_Table[count%10];
P1 = 0x08;
DelayNms(2);
P2 = 0xff;

//学号
P2 = SEG_Table[0];
P1 = 0x40;
DelayNms(2);
P2 = 0xff;
P2 = SEG_Table[6];
P1 = 0x80;
DelayNms(2);
P2 = 0xff;
}
}

void Delay1ms() //@12.000MHz
{
unsigned char i, j;

i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}

void DelayNms(unsigned int t)
{
while(t--)
{
Delay1ms();
}
}

//头文件2222
#include
#include "intrins.h"
unsigned int count = 1994;

void Delay1ms();
void DelayNms(unsigned int t);

//unsigned char code SEG_Table[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x671};//显示0~F的值 共阴极
//0~F段码 //显示0~F的值 共阴极

unsigned char code SEG_Table[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//显示0~F的值 共阳极
//0~F段码 //显示0~F的值 共阳极

void int0_init()
{
EA = 1;
IT0 = 1;
EX0 = 1;
}
void int0_serve() interrupt 0
{
count++;
if(count >= 2000)
{
count = 0;
}
}

void main()
{
int0_init();
while(1)
{
//按键计数
P2 = SEG_Table[count/1000];
P1 = 0x01;
DelayNms(2);
P2 = 0xff;

P2 = SEG_Table[(count%1000)/100];
P1 = 0x02;
DelayNms(2);
P2 = 0xff;

P2 = SEG_Table[(count%100)/10];
P1 = 0x04;
DelayNms(2);
P2 = 0xff;

P2 = SEG_Table[count%10];
P1 = 0x08;
DelayNms(2);
P2 = 0xff;

//学号
P2 = SEG_Table[0];
P1 = 0x40;
DelayNms(2);
P2 = 0xff;
P2 = SEG_Table[6];
P1 = 0x80;
DelayNms(2);
P2 = 0xff;
}
}

void Delay1ms() //@12.000MHz
{
unsigned char i, j;

i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}

void DelayNms(unsigned int t)
{
while(t--)
{
Delay1ms();
}
}

亮了(0)
回复

//头文件3333
#include
#include "intrins.h"
unsigned int flag = 0;
unsigned char time_count = 0;

void Delay1ms();
void DelayNms(unsigned int t);
unsigned char LED_Table[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

//unsigned char code SEG_Table[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x671};//显示0~F的值 共阴极
//0~F段码 //显示0~F的值 共阴极

unsigned char code SEG_Table[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//显示0~F的值 共阳极
//0~F段码 //显示0~F的值 共阳极

void Timer0_init()
{
TMOD |= 0X01;
TH0 = (65535-50000)/256;
TL0 = (65535-50000)%256;
EA = 1;
ET0 = 1;
TR0 = 1;
}

void Timer_0serve() interrupt 1
{
TH0 = (65535-50000)/256;
TL0 = (65535-50000)%256;
flag++;
if(flag == 20)
{
flag = 0;
time_count++;
if(time_count >= 16) // 学号为06
{
time_count = 16;
}
}
}

void main()
{
Timer0_init();
while(1)
{
P2 = SEG_Table[time_count/10];
DelayNms(10);
P1 = 0x02;
P2 = 0xff;

P2 = SEG_Table[time_count%10];
DelayNms(10);
P1 = 0x01;
P2 = 0xff;

}
}

void Delay1ms() //@12.000MHz
{
unsigned char i, j;

i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}

void DelayNms(unsigned int t)
{
while(t--)
{
Delay1ms();
}
}

//头文件3333
#include
#include "intrins.h"
unsigned int flag = 0;
unsigned char time_count = 0;

void Delay1ms();
void DelayNms(unsigned int t);
unsigned char LED_Table[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

//unsigned char code SEG_Table[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x671};//显示0~F的值 共阴极
//0~F段码 //显示0~F的值 共阴极

unsigned char code SEG_Table[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//显示0~F的值 共阳极
//0~F段码 //显示0~F的值 共阳极

void Timer0_init()
{
TMOD |= 0X01;
TH0 = (65535-50000)/256;
TL0 = (65535-50000)%256;
EA = 1;
ET0 = 1;
TR0 = 1;
}

void Timer_0serve() interrupt 1
{
TH0 = (65535-50000)/256;
TL0 = (65535-50000)%256;
flag++;
if(flag == 20)
{
flag = 0;
time_count++;
if(time_count >= 16) // 学号为06
{
time_count = 16;
}
}
}

void main()
{
Timer0_init();
while(1)
{
P2 = SEG_Table[time_count/10];
DelayNms(10);
P1 = 0x02;
P2 = 0xff;

P2 = SEG_Table[time_count%10];
DelayNms(10);
P1 = 0x01;
P2 = 0xff;

}
}

void Delay1ms() //@12.000MHz
{
unsigned char i, j;

i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}

void DelayNms(unsigned int t)
{
while(t--)
{
Delay1ms();
}
}

亮了(0)
回复

//头文件4444
#include
#include "intrins.h"
sbit key = P3^3;
unsigned int count = 1000;
unsigned char i;


void Delay1ms();
void DelayNms(unsigned int t);
void SendChar(unsigned char dat);
void SendString(unsigned char *s);
unsigned char LED_Table[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

//unsigned char code SEG_Table[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x671};//显示0~F的值 共阴极
//0~F段码 //显示0~F的值 共阴极

unsigned char code SEG_Table[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//显示0~F的值 共阳极
//0~F段码 //显示0~F的值 共阳极

void count0_serve(void) interrupt 3
{
count++;
if(count >= 100)
{
count = 0;
}
}
void seg_disp(unsigned int value)
{
P2 = SEG_Table[value/10];
DelayNms(200);
P1 = 0x02;
P2 = 0xff;

P2 = SEG_Table[value%10];
DelayNms(200);
P1 = 0x01;
P2 = 0xff;
}
void main()
{
TMOD = 0x20; //方式2
TH1 = TL1 =0xfd;//9600bit/s
EA = 1;
ET1 = 1;
TR1=1;
SCON =0x40;
TCON |=0x10;

SendString("Test String");
SendString("\r\n");
while(1)
{
SendString("InitValue is:94");
seg_disp(count);
}
}

void Delay1ms() //@12.000MHz
{
unsigned char i, j;

i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}

void DelayNms(unsigned int t)
{
while(t--)
{
Delay1ms();
}
}

void SendChar(unsigned char dat)
{
SBUF = dat;
while(TI==0);//等待发送完成 TI=1
TI=0;
}
void SendString(unsigned char *s)
{
while(*s!='\0')
{
SendChar(*s);
s++;
}
}

//头文件4444
#include
#include "intrins.h"
sbit key = P3^3;
unsigned int count = 1000;
unsigned char i;


void Delay1ms();
void DelayNms(unsigned int t);
void SendChar(unsigned char dat);
void SendString(unsigned char *s);
unsigned char LED_Table[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

//unsigned char code SEG_Table[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x671};//显示0~F的值 共阴极
//0~F段码 //显示0~F的值 共阴极

unsigned char code SEG_Table[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//显示0~F的值 共阳极
//0~F段码 //显示0~F的值 共阳极

void count0_serve(void) interrupt 3
{
count++;
if(count >= 100)
{
count = 0;
}
}
void seg_disp(unsigned int value)
{
P2 = SEG_Table[value/10];
DelayNms(200);
P1 = 0x02;
P2 = 0xff;

P2 = SEG_Table[value%10];
DelayNms(200);
P1 = 0x01;
P2 = 0xff;
}
void main()
{
TMOD = 0x20; //方式2
TH1 = TL1 =0xfd;//9600bit/s
EA = 1;
ET1 = 1;
TR1=1;
SCON =0x40;
TCON |=0x10;

SendString("Test String");
SendString("\r\n");
while(1)
{
SendString("InitValue is:94");
seg_disp(count);
}
}

void Delay1ms() //@12.000MHz
{
unsigned char i, j;

i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}

void DelayNms(unsigned int t)
{
while(t--)
{
Delay1ms();
}
}

void SendChar(unsigned char dat)
{
SBUF = dat;
while(TI==0);//等待发送完成 TI=1
TI=0;
}
void SendString(unsigned char *s)
{
while(*s!='\0')
{
SendChar(*s);
s++;
}
}

亮了(0)
回复

#include 4444
#include /*包含移位函数等的头文件*/
#include
unsigned char code seg_code[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
sbit key=P3^4;
unsigned int n;
void delay(unsigned int time) {
while (time--);

}
void SendChar(unsigned char dat )
{
SBUF=dat; /*待发送数据写入发送缓冲寄存器*/
while(TI==0); /*串口未发送完,等待*/
TI=0; /*一个字节发送完毕,软件将TI标志清0*/
}
void display(unsigned int num) {




P1= seg_code[num%10];
delay(500);

SendChar(seg_code[num%10]);
}

void main( )
{
unsigned char count2=0;
TMOD=0x20;/*设置T1为定时器方式2*/
PCON=0X00;
TH1=0xFD;/*波特率9600*/
TL1=0xFD;
TR1=1; /*启动T1*/
SCON=0x40; /* 串行口初始化为方式1*/
EA=1;
ES=1;
ET1 = 0;
while(1) /*循环*/
{
display(count2);
if(key==0){
delay(50);
count2++;
while(!key){

display(count2);


}
}
}
}

#include 4444
#include /*包含移位函数等的头文件*/
#include
unsigned char code seg_code[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
sbit key=P3^4;
unsigned int n;
void delay(unsigned int time) {
while (time--);

}
void SendChar(unsigned char dat )
{
SBUF=dat; /*待发送数据写入发送缓冲寄存器*/
while(TI==0); /*串口未发送完,等待*/
TI=0; /*一个字节发送完毕,软件将TI标志清0*/
}
void display(unsigned int num) {




P1= seg_code[num%10];
delay(500);

SendChar(seg_code[num%10]);
}

void main( )
{
unsigned char count2=0;
TMOD=0x20;/*设置T1为定时器方式2*/
PCON=0X00;
TH1=0xFD;/*波特率9600*/
TL1=0xFD;
TR1=1; /*启动T1*/
SCON=0x40; /* 串行口初始化为方式1*/
EA=1;
ES=1;
ET1 = 0;
while(1) /*循环*/
{
display(count2);
if(key==0){
delay(50);
count2++;
while(!key){

display(count2);


}
}
}
}

亮了(0)
回复
Re:两数之和c语言刷题123
虎扑游戏中心
步行街主干道最热帖
选三个你认为最漂亮的三个老婆
伤病失业,瞒着老婆输掉28w,零碎的心要如何弥补?
海淀十八年鸡娃终点,高考放榜582分
为何同为华夏子孙男女国家队落差却如此之大?
帮忙取个像霍去病和辛弃疾这种一听就感到不凡的名字,姓温。采用了5元大洋奉上。
jrm帮忙看看投篮姿势(小弟大学院队首发水平打比赛很少投篮)
这救生圈扔得真是让人着急
[解压视频] 能打败女司机的只能是另一个女司机
花生米和酱牛肉,谁是酒桌上的goat?
这位年薪百万的高管竟然如此评价电动汽车的未来,什么水平?
热门游戏-即点即玩
无需下载,足球经理模式一键即玩
《NBA英雄》教练系统上线啦!我选好了,看看你的