當前位置:首頁 » 編程語言 » c語言在屏幕上顯示鍵盤輸入
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言在屏幕上顯示鍵盤輸入

發布時間: 2022-07-27 18:24:48

『壹』 c語言編寫程序用於16LED顯示屏鍵盤輸入漢字LED屏輸出

#include<reg52.h>

#include<intrins.h>

#define uchar unsigned char

#define uint unsigned int

/*下面是引腳連接關系*/

sbit AD_EOC =P2^4; /*轉換完成指示*/

sbit AD_IOCLK =P2^3; /*時 鍾*/

sbit AD_DATIN =P2^2; /*數據入*/

sbit AD_DATOUT=P2^1; /*數據出*/

sbit AD_CS =P2^0; /*片 選*/

uint ad_result; /*存各模擬通道的數據*/

sbit E=P2^7;

sbit rs=P2^6;

sbit rw=P2^5;

sbit S1=P3^0;

sbit S2=P3^1;

sbit S3=P3^2;

sbit S4=P3^3;

sbit S5=P3^4;

sbit S6=P3^5;

sbit S7=P3^6;

sbit S8=P3^7;

sbit S9=P1^5;

sbit S10=P1^6;

sbit S11=P1^7;

sbit S12=P1^0;

uchar code zengzhen[]={"wuhanligongdaxue"};

uchar code zengzhen1[]={"Cha : mV "};

uint zengzhen2[8];

uint i,j;

uchar sum;

void delay(uint z)

{

uint x,y;

for(x=z;x>0;x--)

for(y=110;y>0;y--);

}


void write_com(uchar com)

{


rs=0;

rw=0;

P0=com;

E=0;

delay(1);

E=1;

delay(1);

E=0;

}


void write_date(uchar date)

{


rs=1;

rw=0;

P0=date;

E=0;

delay(1);

E=1;

delay(1);

E=0;

}



void init()

{

E=0;

write_com(0x38);

write_com(0x0c);

write_com(0x06);

write_com(0x01);

}


/*啟動A/D轉換,並讀取上次轉換結果*/

uint read2543(CHN)

{

uchar i,temp;

uint read_ad_data = 0;

CHN=CHN<<4;

AD_IOCLK=0;

AD_CS=1;

AD_CS=0;

temp=CHN;

for(i=0;i<12;i++)

{

read_ad_data=read_ad_data<<1;

if((temp&0x80)!=0){AD_DATIN=1;}

else{AD_DATIN=0;}

if(AD_DATOUT){read_ad_data=read_ad_data+1;}

AD_IOCLK =1;

_nop_();_nop_();_nop_();_nop_();

AD_IOCLK =0;

_nop_();_nop_();_nop_();_nop_();

temp=temp<<1;

}

AD_CS=1;

read_ad_data=read_ad_data&0x0fff;


return(read_ad_data);

}


void display(uint k,uchar add)

{

uchar a,b,c,d;

float j=k*4.444/4.095;

uint i=j/1;

a=i/1000;

b=i%1000/100;

c=i%100/10;

d=i%10;

write_com(add);

write_date(a+0x30);

write_date(b+0x30);

write_date(c+0x30);

write_date(d+0x30);

delay(300);

}


/************顯示程序*************/



/*主 程序*/



void scan()

{

if(S1==0)

{

delay(5);

if(S1==0)

{

while(!S1);

sum=1;

}

}

if(S2==0)

{

delay(5);

if(S2==0)

{

while(!S2);

sum=2;

}

}

if(S3==0)

{

delay(5);

if(S3==0)

{

while(!S3);

sum=3;

}

}

if(S4==0)

{

delay(5);

if(S4==0)

{

while(!S4);

sum=4;

}

}

if(S5==0)

{

delay(5);

if(S5==0)

{

while(!S5);

sum=5;

}

}

if(S6==0)

{

delay(5);

if(S6==0)

{

while(!S6);

sum=6;

}

}

if(S7==0)

{

delay(5);

if(S7==0)

{

while(!S7);

sum=7;

}

}

if(S8==0)

{

delay(5);

if(S8==0)

{

while(!S8);

sum=8;

}

}

if(S9==0)

{

delay(5);

if(S9==0)

{

while(!S9);

sum=9;

}

}

if(S10==0)

{

delay(5);

if(S10==0)

{

while(!S10);

sum=10;

}

}

if(S11==0)

{

delay(5);

if(S11==0)

{

while(!S11);

sum=11;

}

}

if(S12==0)

{

delay(5);

if(S12==0)

{

while(!S12);

sum=12;

}

}

}



void fw()

{

write_com(0x80+0x40+2);

for(j=0;j<12;j++)

{

write_date(zengzhen1[j]);

delay(5);

}

}

void main(void)

{

uchar h ;

uint s=0;

init();

delay(23);

write_com(0x80);

for(j=0;j<16;j++)

{

write_date(zengzhen[j]);

delay(5);

}


write_com(0x80+0x40+2);

for(j=0;j<12;j++)

{

write_date(zengzhen1[j]);

delay(5);

}


while(1)

{


if(sum==12)

{

scan();

if(sum!=12)

{

init();

delay(23);

write_com(0x80);

for(j=0;j<16;j++)

{

write_date(zengzhen[j]);

delay(5);

}


write_com(0x80+0x40+2);

for(j=0;j<12;j++)

{

write_date(zengzhen1[j]);

delay(5);

}

}

}


if(sum==11)

{

scan();

if(sum!=11)

{

fw();

}

}

scan();

if(sum==1)

{

for(h=0;h<15;h++)

{

ad_result=read2543(0);

while(!AD_EOC);

s+=ad_result;

}

s=s/15;

write_com(0x80+0x40+5);

write_date(0+0x30);

display(s,0x80+0x40+7);

s=0;


}

if(sum==2)

{

for(h=0;h<15;h++)

{

ad_result=read2543(1);

while(!AD_EOC);

s+=ad_result;

}

s=s/15;

write_com(0x80+0x40+5);

write_date(1+0x30);

display(s,0x80+0x40+7);

s=0;

}

if(sum==3)

{

for(h=0;h<15;h++)

{

ad_result=read2543(2);

while(!AD_EOC);

s+=ad_result;

}

s=s/15;

write_com(0x80+0x40+5);

write_date(2+0x30);

display(s,0x80+0x40+7);

s=0;

}

if(sum==4)

{

for(h=0;h<15;h++)

{

ad_result=read2543(3);

while(!AD_EOC);

s+=ad_result;

}

s=s/15;

write_com(0x80+0x40+5);

write_date(3+0x30);

display(s,0x80+0x40+7);

s=0;

}

if(sum==5)

{

for(h=0;h<15;h++)

{

ad_result=read2543(4);

while(!AD_EOC);

s+=ad_result;

}

s=s/15;

write_com(0x80+0x40+5);

write_date(4+0x30);

display(s,0x80+0x40+7);

s=0;

}

if(sum==6)

{

for(h=0;h<15;h++)

{

ad_result=read2543(5);

while(!AD_EOC);

s+=ad_result;

}

s=s/15;

write_com(0x80+0x40+5);

write_date(5+0x30);

display(s,0x80+0x40+7);

s=0;

}

if(sum==7)

{

for(h=0;h<15;h++)

{

ad_result=read2543(6);

while(!AD_EOC);

s+=ad_result;

}

s=s/15;

write_com(0x80+0x40+5);

write_date(6+0x30);

display(s,0x80+0x40+7);

s=0;

}

if(sum==8)

{

for(h=0;h<15;h++)

{

ad_result=read2543(7);

while(!AD_EOC);

s+=ad_result;

}

s=s/15;

write_com(0x80+0x40+5);

write_date(7+0x30);

display(s,0x80+0x40+7);

s=0;

}

if(sum==9)

{

for(h=0;h<15;h++)

{

ad_result=read2543(8);

while(!AD_EOC);

s+=ad_result;

}

s=s/15;

write_com(0x80+0x40+5);

write_date(8+0x30);

display(s,0x80+0x40+7);

s=0;

}

if(sum==10)

{

for(h=0;h<15;h++)

{

ad_result=read2543(9);

while(!AD_EOC);

s+=ad_result;

}

s=s/15;

write_com(0x80+0x40+5);

write_date(9+0x30);

display(s,0x80+0x40+7);

s=0;

}

if(sum==11)

{

for(h=0;h<15;h++)

{

ad_result=read2543(10);

while(!AD_EOC);

s+=ad_result;

}

s=s/15;

write_com(0x80+0x40+5);

write_date(1+0x30);

write_date(0+0x30);

write_date(':');

display(s,0x80+0x40+8);

write_date('m');

write_date('V');

s=0;

}

if(sum==12)

{

/*delay(100);

for(h=0;h<8;h++)

{

ad_result=read2543(h);

while(!AD_EOC);

ad_result=read2543(h);

zengzhen2[h]=ad_result;

}

*/

zengzhen2[0]=read2543(0);

while(!AD_EOC);

display(zengzhen2[0],0x80);

zengzhen2[1]=read2543(1);

while(!AD_EOC);

display(zengzhen2[1],0x84);

zengzhen2[2]=read2543(2);

while(!AD_EOC);

display(zengzhen2[2],0x88);

zengzhen2[3]=read2543(3);

while(!AD_EOC);

display(zengzhen2[3],0x8c);

zengzhen2[4]=read2543(4);

while(!AD_EOC);

display(zengzhen2[4],0x80+0x40);

zengzhen2[5]=read2543(5);

while(!AD_EOC);

display(zengzhen2[5],0x80+0x40+4);

zengzhen2[6]=read2543(6);

while(!AD_EOC);

display(zengzhen2[6],0x80+0x40+8);

zengzhen2[7]=read2543(7);

while(!AD_EOC);

display(zengzhen2[7],0x80+0x40+12);

}


}

}

望採納謝謝

『貳』 編寫c語言程序,對於從鍵盤上輸入的一行字元,該程序能將其依次顯示在屏幕上.

#include<stdio.h>
#include<string.h>
intmain(){
chars[100];
gets(s);
printf("%s",s);
return0;
}

『叄』 C語言編程題:從鍵盤輸入一個小寫字母,在屏幕上顯示其對應的大寫字母

#include<stdio.h>

int main()

{

char ch;

printf("請輸入一個小寫字母:");

scanf("%c",&ch);

ch=ch-32;

printf("大寫字母是:%c ",ch);

return 0;

}

可以加一個判斷

#include<stdio.h>

int main()

{

char ch;

printf("請輸入一個小寫字母:");

scanf("%c",&ch);

while(!(ch>='a'&&ch<='z'))

{printf("輸入錯誤,請重新輸入一個小寫字母!");

scanf("%c",&ch);

}

ch=ch-32;

printf("大寫字母是:%c ",ch);

return 0;

}

文件輸入/輸出

在C語言中,輸入和輸出是經由標准庫中的一組函數來實現的。在ANSI C中,這些函數被定義在頭文件;中。

標准輸入/輸出

有三個標准輸入/輸出是標准I/O庫預先定義的:

stdin標准輸入

stdout標准輸出

stderr輸入輸出錯誤

以上內容參考:網路-c語言

『肆』 C語言題`任意從鍵盤上輸入一個字元`並把所輸字元在屏幕上輸出

#include"stdafx.h"

#include<math.h>

#include<malloc.h>

intmain(intargc,char*argv[])

{

inti;

char*pTemp;

i=0;

pTemp=(char*)malloc(100);

printf("輸入字元,按q結束 ");

while(1)

{

printf("請輸入字元:");

gets(pTemp);

if(*pTemp=='q')

{

break;

}

printf("你輸入的字元:%s ",pTemp);

i++;

}

return0;

}

『伍』 c語言在屏幕上輸出下面的結果,輸出數據的行數通過鍵盤輸入,要求在5~20行之間。

#include "stdio.h"

int main(){

int n,i,j,k,t;

printf("請輸入n(int 4<n<21)... n=");

if(scanf("%d",&n)==1 && n>4 && n<21){

for(k=3,i=0;i<n;i++,k+=3){

for(t=k,j=0;j<4;j++,t+=2)

printf("%3d",t);

putchar(' ');

}

}

else

printf("輸入錯誤,退出... ");

return 0;

}

執行結果:

『陸』 C語言程序,鍵盤輸入你的名字和學號在屏幕顯示: Hello,名字 你的學號是,xxx

1、打開Codeblock。

『柒』 簡單的C語言編程問題。 題一:從鍵盤輸入字元串「How are you」,並將其顯示在屏幕上。 下

#include<stdio.h>
intmain()
{chars[200];
gets(s);
puts(s);
return0;
}

#include<stdio.h>
intmain()
{inti,n;
printf("要輸入幾個字元串:");
scanf("%d%*c",&n);
chars[n][80];
for(i=0;i<n;i++)
gets(s[i]);
printf("輸入的字元串是: ");
for(i=0;i<n;i++)
puts(s[i]);
return0;
}

『捌』 C語言編程:從鍵盤輸入兩個實數後,屏幕顯示菜單如下內容

#include<stdio.h>

char *Text[] = {"退出", "兩數之和",

                 "兩數之差", "兩數乘積",

                 "兩數相乘之商"};

int main(void)

{

    double n1, n2, result;

    int choice;

    printf("請輸入兩個實數:");

    scanf("%lf%lf", &n1, &n2);

    while(1)

    {

        for(int i = 1; i < sizeof(Text)/sizeof(char *); i++)

            printf("%d.%s%s ", i, "輸出", Text[i]);

        printf("5.%s ", Text[0]);

        printf("請輸入你的選擇: ");

        scanf("%d", &choice);

        if(choice == 5)

        {

            printf("退出關閉程序 ");

            return 0;

        }

        if(choice < 0 || choice > 4)

        {

            printf("抱歉,查無此選項 ");

            continue;

        }

        switch(choice)

        {

            case 1:

            {

                result = n1 + n2;

                break;

            }

            case 2:

            {

                result = n1 - n2;

                break;

            }

            case 3:

            {

                result = n1 * n2;

                break;

            }

            case 4:

            {

                result = n1 / n2;

                break;

            }

        }

        printf("%s%s:%.2lf ", Text[choice], "為", result);

    }

    return 0;

}

『玖』 C語言怎麼把剛在屏幕上輸入的數據馬上顯示出來

話不多說,直接寫代碼,按照你說的我理解為:輸入沒有限制的字元數,輸入完了用屏幕顯示出來,每一個字元中間都要有一個空格作為間隔,對嗎?,代碼如下:
#include<stdio.h>
void
main()
{
int
x,y=0;
char
*a="123456";//在這個「」裡面存放你想輸出的字元,就可以了,接下來用for輸出。
for(x=0;a[y]!=0;x++)
{
printf("%c
",a[y]);
y++;
}
getchar();
}