* TFTP client compatible with RFC-1350 * compile under visiual c++ or borland c++ * author email: yuyushine@163.com ***************************************************/ #define _VC /* if compile under visiual c++ else undefine this*/ #include <stdio.h> #include <winsock.h> #include <conio.h> #ifndef MAKEWORD #define MAKEWORD(l,h) ((WORD)(((BYTE)(l))|(((WORD)(BYTE)(h))<<8))) #endif #define WSA_MAJOR_VERSION 1 #define WSA_MINOR_VERSION 1 #define WSA_VERSION MAKEWORD(WSA_MAJOR_VERSION, WSA_MINOR_VERSION)
標簽: compatible borland compile visiual
上傳時間: 2014-01-15
上傳用戶:yuchunhai1990
兩個鏈表的交集 #include<stdio.h> #include<stdlib.h> typedef struct Node{ int data; struct Node *next; }Node; void initpointer(struct Node *p){ p=NULL; } int printlist(struct Node* head){ int flag=1; head=head->next; /* 因為標記1的地方你用了頭結點,所以第一個數據域無效,應該從下一個頭元結點開始 */ if(head==NULL) printf("NULL\n"); else { while(head!=NULL) { if(flag==1) { printf("%d",head->data); flag=0; } else { printf(" %d",head->data); } head=head->next; } printf("\n"); } return 0; } struct Node *creatlist(struct Node *head) { int n; struct Node *p1=(struct Node *)malloc(sizeof(struct Node)); p1->next=NULL; while(scanf("%d",&n),n!=-1) { struct Node *pnode=(struct Node *)malloc(sizeof(struct Node)); pnode->next=NULL; pnode->data=n; if(head==NULL) head=pnode; p1->next=pnode; p1=pnode; } return head; } struct Node *Intersect(struct Node *head1, struct Node *head2) { struct Node *p1=head1,*p2=head2;/*我這里沒有用頭指針和頭結點,這里是首元結點head1里面就是第一個數據,一定要理解什么事頭指針, 頭結點,和首元結點 具體你一定要看這個博客:http://blog.sina.com.cn/s/blog_71e7e6fb0101lipz.html*/ struct Node *head,*p,*q; head = (struct Node *)malloc(sizeof(struct Node)); head->next = NULL; p = head; while( (p1!=NULL)&&(p2!=NULL) ) { if (p1->data == p2->data) { q = (struct Node *)malloc(sizeof(struct Node)); q->data = p1->data; q->next = NULL; p->next = q;//我可以認為你這里用了頭結點,也就是說第一個數據域無效 **標記1** p = q; p1 = p1->next; p2 = p2->next; } else if (p1->data < p2->data) { p1 = p1->next; } else { p2 = p2->next; } } return head; } int main() { struct Node *head=NULL,*headt=NULL,*t; //initpointer(head);//這里的函數相當于head=NULL; // initpointer(headt);//上面已經寫了headt=NULL那么這里可以不用調用這個函數 head=creatlist(head); headt=creatlist(headt); t=Intersect(head,headt); printlist(t); }
標簽: c語言編程
上傳時間: 2015-04-27
上傳用戶:coco2017co
#include<stdio.h> #include<stdlib.h> #include<conio.h> #include<string.h> main(void) { char new_name[4], name[4]; int new_sn ,sn; printf(" 【注冊】\n\n"); printf("請輸入用戶名(四位英文字母):"); scanf("%s", &new_name); printf("請輸入密碼(六位數字):") ; scanf("%d" ,&new_sn); /*system("PAUSE");*/ system("CLS");/*清屏*/ /*system("PAUSE");*/ printf(" 【登陸】\n\n"); printf("輸入用戶名:"); scanf("%s" , &name); if(!strcmp(new_name,name)){printf("輸入用戶名錯誤!"); }/*判斷用戶是否正確*/ printf("輸入密碼:"); scanf("%d" , &sn); if(new_sn != sn){printf("輸入密碼錯誤!"); }/*判斷密碼是否正確*/ system("CLS"); printf("恭喜你,登陸成功!\n"); getchar(); return 0; }
標簽: C語言
上傳時間: 2015-12-30
上傳用戶:gjatd1987
實驗源代碼 //Warshall.cpp #include<stdio.h> void warshall(int k,int n) { int i , j, t; int temp[20][20]; for(int a=0;a<k;a++) { printf("請輸入矩陣第%d 行元素:",a); for(int b=0;b<n;b++) { scanf ("%d",&temp[a][b]); } } for(i=0;i<k;i++){ for( j=0;j<k;j++){ if(temp[ j][i]==1) { for(t=0;t<n;t++) { temp[ j][t]=temp[i][t]||temp[ j][t]; } } } } printf("可傳遞閉包關系矩陣是:\n"); for(i=0;i<k;i++) { for( j=0;j<n;j++) { printf("%d", temp[i][ j]); } printf("\n"); } } void main() { printf("利用 Warshall 算法求二元關系的可傳遞閉包\n"); void warshall(int,int); int k , n; printf("請輸入矩陣的行數 i: "); scanf("%d",&k); 四川大學實驗報告 printf("請輸入矩陣的列數 j: "); scanf("%d",&n); warshall(k,n); }
上傳時間: 2016-06-27
上傳用戶:梁雪文以
#include <stdlib.h> #include<stdio.h> #include <malloc.h> #define stack_init_size 100 #define stackincrement 10 typedef struct sqstack { int *base; int *top; int stacksize; } sqstack; int StackInit(sqstack *s) { s->base=(int *)malloc(stack_init_size *sizeof(int)); if(!s->base) return 0; s->top=s->base; s->stacksize=stack_init_size; return 1; } int Push(sqstack *s,int e) { if(s->top-s->base>=s->stacksize) { s->base=(int *)realloc(s->base,(s->stacksize+stackincrement)*sizeof(int)); if(!s->base) return 0; s->top=s->base+s->stacksize; s->stacksize+=stackincrement; } *(s->top++)=e; return e; } int Pop(sqstack *s,int e) { if(s->top==s->base) return 0; e=*--s->top; return e; } int stackempty(sqstack *s) { if(s->top==s->base) { return 1; } else { return 0; } } int conversion(sqstack *s) { int n,e=0,flag=0; printf("輸入要轉化的十進制數:\n"); scanf("%d",&n); printf("要轉化為多少進制:\n"); scanf("%d",&flag); printf("將十進制數%d 轉化為%d 進制是:\n",n,flag); while(n) { Push(s,n%flag); n=n/flag; } while(!stackempty(s)) { e=Pop(s,e); switch(e) { case 10: printf("A"); break; case 11: printf("B"); break; case 12: printf("C"); break; case 13: printf("D"); break; case 14: printf("E"); break; case 15: printf("F"); break; default: printf("%d",e); } } printf("\n"); return 0; } int main() { sqstack s; StackInit(&s); conversion(&s); return 0; }
上傳時間: 2016-12-08
上傳用戶:愛你198
#include <malloc.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define NULL 0 #define MaxSize 30 typedef struct athletestruct /*運動員*/ { char name[20]; int score; /*分數*/ int range; /**/ int item; /*項目*/ }ATH; typedef struct schoolstruct /*學校*/ { int count; /*編號*/ int serial; /**/ int menscore; /*男選手分數*/ int womenscore; /*女選手分數*/ int totalscore; /*總分*/ ATH athlete[MaxSize]; /**/ struct schoolstruct *next; }SCH; int nsc,msp,wsp; int ntsp; int i,j; int overgame; int serial,range; int n; SCH *head,*pfirst,*psecond; int *phead=NULL,*pafirst=NULL,*pasecond=NULL; void create(); void input () { char answer; head = (SCH *)malloc(sizeof(SCH)); /**/ head->next = NULL; pfirst = head; answer = 'y'; while ( answer == 'y' ) { Is_Game_DoMain: printf("\nGET Top 5 when odd\nGET Top 3 when even"); printf("\n輸入運動項目序號 (x<=%d):",ntsp); scanf("%d",pafirst); overgame = *pafirst; if ( pafirst != phead ) { for ( pasecond = phead ; pasecond < pafirst ; pasecond ++ ) { if ( overgame == *pasecond ) { printf("\n這個項目已經存在請選擇其他的數字\n"); goto Is_Game_DoMain; } } } pafirst = pafirst + 1; if ( overgame > ntsp ) { printf("\n項目不存在"); printf("\n請重新輸入"); goto Is_Game_DoMain; } switch ( overgame%2 ) { case 0: n = 3;break; case 1: n = 5;break; } for ( i = 1 ; i <= n ; i++ ) { Is_Serial_DoMain: printf("\n輸入序號 of the NO.%d (0<x<=%d): ",i,nsc); scanf("%d",&serial); if ( serial > nsc ) { printf("\n超過學校數目,請重新輸入"); goto Is_Serial_DoMain; } if ( head->next == NULL ) { create(); } psecond = head->next ; while ( psecond != NULL ) { if ( psecond->serial == serial ) { pfirst = psecond; pfirst->count = pfirst->count + 1; goto Store_Data; } else { psecond = psecond->next; } } create(); Store_Data: pfirst->athlete[pfirst->count].item = overgame; pfirst->athlete[pfirst->count].range = i; pfirst->serial = serial; printf("Input name:) : "); scanf("%s",pfirst->athlete[pfirst->count].name); } printf("\n繼續輸入運動項目(y&n)?"); answer = getchar(); printf("\n"); } } void calculate() /**/ { pfirst = head->next; while ( pfirst->next != NULL ) { for (i=1;i<=pfirst->count;i++) { if ( pfirst->athlete[i].item % 2 == 0 ) { switch (pfirst->athlete[i].range) { case 1:pfirst->athlete[i].score = 5;break; case 2:pfirst->athlete[i].score = 3;break; case 3:pfirst->athlete[i].score = 2;break; } } else { switch (pfirst->athlete[i].range) { case 1:pfirst->athlete[i].score = 7;break; case 2:pfirst->athlete[i].score = 5;break; case 3:pfirst->athlete[i].score = 3;break; case 4:pfirst->athlete[i].score = 2;break; case 5:pfirst->athlete[i].score = 1;break; } } if ( pfirst->athlete[i].item <=msp ) { pfirst->menscore = pfirst->menscore + pfirst->athlete[i].score; } else { pfirst->womenscore = pfirst->womenscore + pfirst->athlete[i].score; } } pfirst->totalscore = pfirst->menscore + pfirst->womenscore; pfirst = pfirst->next; } } void output() { pfirst = head->next; psecond = head->next; while ( pfirst->next != NULL ) { // clrscr(); printf("\n第%d號學校的結果成績:",pfirst->serial); printf("\n\n項目的數目\t學校的名字\t分數"); for (i=1;i<=ntsp;i++) { for (j=1;j<=pfirst->count;j++) { if ( pfirst->athlete[j].item == i ) { printf("\n %d\t\t\t\t\t\t%s\n %d",i,pfirst->athlete[j].name,pfirst->athlete[j].score);break; } } } printf("\n\n\n\t\t\t\t\t\t按任意建 進入下一頁"); getchar(); pfirst = pfirst->next; } // clrscr(); printf("\n運動會結果:\n\n學校編號\t男運動員成績\t女運動員成績\t總分"); pfirst = head->next; while ( pfirst->next != NULL ) { printf("\n %d\t\t %d\t\t %d\t\t %d",pfirst->serial,pfirst->menscore,pfirst->womenscore,pfirst->totalscore); pfirst = pfirst->next; } printf("\n\n\n\t\t\t\t\t\t\t按任意建結束"); getchar(); } void create() { pfirst = (struct schoolstruct *)malloc(sizeof(struct schoolstruct)); pfirst->next = head->next ; head->next = pfirst ; pfirst->count = 1; pfirst->menscore = 0; pfirst->womenscore = 0; pfirst->totalscore = 0; } void Save() {FILE *fp; if((fp = fopen("school.dat","wb"))==NULL) {printf("can't open school.dat\n"); fclose(fp); return; } fwrite(pfirst,sizeof(SCH),10,fp); fclose(fp); printf("文件已經成功保存\n"); } void main() { system("cls"); printf("\n\t\t\t 運動會分數統計\n"); printf("輸入學校數目 (x>= 5):"); scanf("%d",&nsc); printf("輸入男選手的項目(x<=20):"); scanf("%d",&msp); printf("輸入女選手項目(<=20):"); scanf("%d",&wsp); ntsp = msp + wsp; phead = (int *)calloc(ntsp,sizeof(int)); pafirst = phead; pasecond = phead; input(); calculate(); output(); Save(); }
標簽: 源代碼
上傳時間: 2016-12-28
上傳用戶:150501
#include "string.h" #include "ctype.h" #include "stdio.h" search(char pd[]) {FILE *fp; int time=0,i=0,j=0,add[80],k=0,m; char *ch, str[900]; m=strlen(pd); if((fp=fopen("haha.txt","r"))==NULL) { printf("Cannot open this file\n"); exit(0); } for(;!feof(fp);i++) { str[i]=fgetc(fp); if(tolower(str[i])==tolower(pd[k])) {k++; if(k==m) if(!isalpha(i-m)&&!isalpha((str[i++]=fgetc(fp)))) { time++; add[j]=i-m+1; j++; k=0; } else k=0; } } if(time) { printf("The time is:%d\n",time); printf("The adders is:\n"); for(i=0;i
標簽: 查詢學會少年宮
上傳時間: 2016-12-29
上傳用戶:767483511
#include "string.h" #include "ctype.h" #include "stdio.h" search(char pd[]) {FILE *fp; int time=0,i=0,j=0,add[80],k=0,m; char *ch, str[900]; m=strlen(pd); if((fp=fopen("haha.txt","r"))==NULL) { printf("Cannot open this file\n"); exit(0); } for(;!feof(fp);i++) { str[i]=fgetc(fp); if(tolower(str[i])==tolower(pd[k])) {k++; if(k==m) if(!isalpha(i-m)&&!isalpha((str[i++]=fgetc(fp)))) { time++; add[j]=i-m+1; j++; k=0; } else k=0; } } if(time) { printf("The time is:%d\n",time); printf("The adders is:\n"); for(i=0;i<j;i++) printf("%5d",add[i]); if(i%5==0) printf("\n"); getch(); fclose(fp); } else printf("Sorry!Cannot find the word(^_^)"); } main() { char pd[10],choose='y'; int flag=1; while(flag) {printf("In put the word you want to seqarch:"); scanf("%s",pd); search(strlwr(pd)); printf("\nWould you want to continue?(Y/N):"); getchar(); scanf("%c",&choose); if((tolower(choose))=='n') flag=0; else flag=1; } printf("Thanks for your using!Bye-bye!\n"); getch(); }
標簽: 學生專用
上傳時間: 2016-12-29
上傳用戶:767483511
1.Describe a Θ(n lg n)-time algorithm that, given a set S of n integers and another integer x, determines whether or not there exist two elements in S whose sum is exactly x. (Implement exercise 2.3-7.) #include<stdio.h> #include<stdlib.h> void merge(int arr[],int low,int mid,int high){ int i,k; int *tmp=(int*)malloc((high-low+1)*sizeof(int)); int left_low=low; int left_high=mid; int right_low=mid+1; int right_high=high; for(k=0;left_low<=left_high&&right_low<=right_high;k++) { if(arr[left_low]<=arr[right_low]){ tmp[k]=arr[left_low++]; } else{ tmp[k]=arr[right_low++]; } } if(left_low<=left_high){ for(i=left_low;i<=left_high;i++){ tmp[k++]=arr[i]; } } if(right_low<=right_high){ for(i=right_low;i<=right_high;i++) tmp[k++]=arr[i]; } for(i=0;i<high-low+1;i++) arr[low+i]=tmp[i]; } void merge_sort(int a[],int p,int r){ int q; if(p<r){ q=(p+r)/2; merge_sort(a,p,q); merge_sort(a,q+1,r); merge(a,p,q,r); } } int main(){ int a[8]={3,5,8,6,4,1,1}; int i,j; int x=10; merge_sort(a,0,6); printf("after Merging-Sort:\n"); for(i=0;i<7;i++){ printf("%d",a[i]); } printf("\n"); i=0;j=6; do{ if(a[i]+a[j]==x){ printf("exist"); break; } if(a[i]+a[j]>x) j--; if(a[i]+a[j]<x) i++; }while(i<=j); if(i>j) printf("not exist"); system("pause"); return 0; }
上傳時間: 2017-04-01
上傳用戶:糖兒水嘻嘻
/****************temic*********t5557***********************************/ #include <at892051.h> #include <string.h> #include <intrins.h> #include <stdio.h> #define uchar unsigned char #define uint unsigned int #define ulong unsigned long //STC12C2051AD的SFR定義 sfr WDT_CONTR = 0xe1;//stc2051的看門狗?????? /**********全局常量************/ //寫卡的命令 #define write_command0 0//寫密碼 #define write_command1 1//寫配置字 #define write_command2 2//密碼寫數據 #define write_command3 3//喚醒 #define write_command4 4//停止命令 #define TRUE 1 #define FALSE 0 #define OK 0 #define ERROR 255 //讀卡的時間參數us #define ts_min 250//270*11.0592/12=249//取近似的整數 #define ts_max 304//330*11.0592/12=304 #define t1_min 73//90*11.0592/12=83:-10調整 #define t1_max 156//180*11.0592/12=166 #define t2_min 184//210*11.0592/12=194 #define t2_max 267//300*11.0592/12=276 //***********不采用中斷處理:采用查詢的方法讀卡時關所有中斷****************/ sbit p_U2270B_Standby = P3^5;//p_U2270B_Standby PIN=13 sbit p_U2270B_CFE = P3^3;//p_U2270B_CFE PIN=6 sbit p_U2270B_OutPut = P3^7;//p_U2270B_OutPut PIN=2 sbit wtd_sck = P1^7;//SPI總線 sbit wtd_si = P1^3; sbit wtd_so = P1^2; sbit iic_data = P1^2;//lcd IIC sbit iic_clk = P1^7; sbit led_light = P1^6;//測試綠燈 sbit led_light1 = P1^5;//測試紅燈 sbit led_light_ok = P1^1;//讀卡成功標志 sbit fengmingqi = P1^5; /***********全局變量************************************/ uchar data Nkey_a[4] = {0xA0, 0xA1, 0xA2, 0xA3};//初始密碼 //uchar idata card_snr[4]; //配置字 uchar data bankdata[28] = {1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7}; //存儲卡上用戶數據(1-7)7*4=28 uchar data cominceptbuff[6] = {1,2,3,4,5,6};//串口接收數組ram uchar command; //第一個命令 uchar command1;// //uint temp; uchar j,i; uchar myaddr = 8; //uchar ywqz_count,time_count; //ywqz jishu: uchar bdata DATA; sbit BIT0 = DATA^0; sbit BIT1 = DATA^1; sbit BIT2 = DATA^2; sbit BIT3 = DATA^3; sbit BIT4 = DATA^4; sbit BIT5 = DATA^5; sbit BIT6 = DATA^6; sbit BIT7 = DATA^7; uchar bdata DATA1; sbit BIT10 = DATA1^0; sbit BIT11 = DATA1^1; sbit BIT12 = DATA1^2; sbit BIT13 = DATA1^3; sbit BIT14 = DATA1^4; sbit BIT15 = DATA1^5; sbit BIT16 = DATA1^6; sbit BIT17 = DATA1^7; bit i_CurrentLevel;//i_CurrentLevel BIT 00H(Saves current level of OutPut pin of U2270B) bit timer1_end; bit read_ok = 0; //緩存定時值,因用同一個定時器 union HLint { uint W; struct { uchar H;uchar L; } B; };//union HLint idata a union HLint data a; //緩存定時值,因用同一個定時器 union HLint0 { uint W; struct { uchar H; uchar L; } B; };//union HLint idata a union HLint0 data b; /**********************函數原型*****************/ //讀寫操作 void f_readcard(void);//全部讀出1~7 AOR喚醒 void f_writecard(uchar x);//根據命令寫不同的內容和操作 void f_clearpassword(void);//清除密碼 void f_changepassword(void);//修改密碼 //功能子函數 void write_password(uchar data *data p);//寫初始密碼或數據 void write_block(uchar x,uchar data *data p);//不能用通用指針 void write_bit(bit x);//寫位 /*子函數區*****************************************************/ void delay_2(uint x) //延時,時間x*10us@12mhz,最小20us@12mhz { x--; x--; while(x) { _nop_(); _nop_(); x--; } _nop_();//WDT_CONTR=0X3C;不能頻繁的復位 _nop_(); } ///////////////////////////////////////////////////////////////////// void initial(void) { SCON = 0x50; //串口方式1,允許接收 //SCON =0x50; //01010000B:10位異步收發,波特率可變,SM2=0不用接收到有效停止位才RI=1, //REN=1允許接收 TMOD = 0x21; //定時器1 定時方式2(8位),定時器0 定時方式1(16位) TCON = 0x40; //設定時器1 允許開始計時(IT1=1) TH1 = 0xfD; //FB 18.432MHz 9600 波特率 TL1 = 0xfD; //fd 11.0592 9600 IE = 0X90; //EA=ES=1 TR1 = 1; //啟動定時器 WDT_CONTR = 0x3c;//使能看門狗 p_U2270B_Standby = 0;//單電源 PCON = 0x00; IP = 0x10;//uart you xian XXXPS PT1 PX1 PT0 PX0 led_light1 = 1; led_light = 0; p_U2270B_OutPut = 1; } /************************************************/ void f_readcard()//讀卡 { EA = 0;//全關,防止影響跳變的定時器計時 WDT_CONTR = 0X3C;//喂狗 p_U2270B_CFE = 1;// delay_2(232); //>2.5ms /* // aor 用喚醒功能來防碰撞 p_U2270B_CFE = 0; delay_2(18);//start gap>150us write_bit(1);//10=操作碼讀0頁 write_bit(0); write_password(&bankdata[24]);//密碼block7 p_U2270B_CFE =1 ;// delay_2(516);//編程及確認時間5.6ms */ WDT_CONTR = 0X3C;//喂狗 led_light = 0; b.W = 0; while(!(read_ok == 1)) { //while(p_U2270B_OutPut);//等一個穩定的低電平?超時判斷? while(!p_U2270B_OutPut);//等待上升沿的到來同步信號檢測1 TR0 = 1; //deng xia jiang while(p_U2270B_OutPut);//等待下降沿 TR0 = 0; a.B.H = TH0; a.B.L = TL0; TH0 = TL0 = 0; TR0 = 1;//定時器晚啟動10個周期 //同步頭 if((324 < a.W) && (a.W < 353)) ;//檢測同步信號1 else { TR0 = 0; TH0 = TL0 = 0; goto read_error; } //等待上升沿 while(!p_U2270B_OutPut); TR0 = 0; a.B.H = TH0; a.B.L = TL0; TH0 = TL0 = 0; TR0 = 1;//b.N1<<=8; if(a.B.L < 195);//0.5p else { TR0 = 0; TH0 = TL0 = 0; goto read_error; } //讀0~7塊的數據 for(j = 0;j < 28;j++) { //uchar i; for(i = 0;i < 16;i++)//8個位 { //等待下降沿的到來 while(p_U2270B_OutPut); TR0 = 0; a.B.H = TH0; a.B.L = TL0; TH0 = TL0 = 0; TR0 = 1; if(t2_max < a.W/*)&&(a.W < t2_max)*/)//1P { b.W >>= 2;//先左移再賦值 b.B.L += 0xc0; i++; } else if(t1_min < a.B.L/*)&&(a.B.L < t1_max)*/)//0.5p { b.W >>= 1; b.B.L += 0x80; } else { TR0 = 0; TH0 = TL0 = 0; goto read_error; } i++; while(!p_U2270B_OutPut);//上升 TR0 = 0; a.B.H = TH0; a.B.L = TL0; TH0 = TL0 = 0; TR0 = 1; if(t2_min < a.W/*)&&(a.W < t2_max)*/)//1P { b.W >>= 2; i++; } else if(t1_min < a.B.L/*a.W)&&(a.B.L < t1_max)*/)//0.5P //else if(!(a.W==0)) { b.W >>= 1; //temp+=0x00; //led_light1=0;led_light=1;delay_2(40000); } else { TR0 = 0; TH0 = TL0 = 0; goto read_error; } i++; } //取出奇位 DATA = b.B.L; BIT13 = BIT7; BIT12 = BIT5; BIT11 = BIT3; BIT10 = BIT1; DATA = b.B.H; BIT17 = BIT7; BIT16 = BIT5; BIT15 = BIT3; BIT14 = BIT1; bankdata[j] = DATA1; } read_ok = 1;//讀卡完成了 read_error: _nop_(); } } /***************************************************/ void f_writecard(uchar x)//寫卡 { p_U2270B_CFE = 1; delay_2(232); //>2.5ms //psw=0 standard write if (x == write_command0)//寫密碼:初始化密碼 { uchar i; uchar data *data p; p = cominceptbuff; p_U2270B_CFE = 0; delay_2(31);//start gap>330us write_bit(1);//寫操作碼1:10 write_bit(0);//寫操作碼0 write_bit(0);//寫鎖定位0 for(i = 0;i < 35;i++) { write_bit(1);//寫數據位1 } p_U2270B_CFE = 1; led_light1 = 0; led_light = 1; delay_2(40000);//測試使用 //write_block(cominceptbuff[4],p); p_U2270B_CFE = 1; bankdata[20] = cominceptbuff[0];//密碼存入 bankdata[21] = cominceptbuff[1]; bankdata[22] = cominceptbuff[2]; bankdata[23] = cominceptbuff[3]; } else if (x == write_command1)//配置卡參數:初始化 { uchar data *data p; p = cominceptbuff; write_bit(1);//寫操作碼1:10 write_bit(0);//寫操作碼0 write_bit(0);//寫鎖定位0 write_block(cominceptbuff[4],p); p_U2270B_CFE= 1; } //psw=1 pssword mode else if(x == write_command2) //密碼寫數據 { uchar data*data p; p = &bankdata[24]; write_bit(1);//寫操作碼1:10 write_bit(0);//寫操作碼0 write_password(p);//發口令 write_bit(0);//寫鎖定位0 p = cominceptbuff; write_block(cominceptbuff[4],p);//寫數據 } else if(x == write_command3)//aor //喚醒 { //cominceptbuff[1]操作碼10 X xxxxxB uchar data *data p; p = cominceptbuff; write_bit(1);//10 write_bit(0); write_password(p);//密碼 p_U2270B_CFE = 1;//此時數據不停的循環傳出 } else //停止操作碼 { write_bit(1);//11 write_bit(1); p_U2270B_CFE = 1; } p_U2270B_CFE = 1; delay_2(560);//5.6ms } /************************************/ void f_clearpassword()//清除密碼 { uchar data *data p; uchar i,x; p = &bankdata[24];//原密碼 p_U2270B_CFE = 0; delay_2(18);//start gap>150us //操作碼10:10xxxxxxB write_bit(1); write_bit(0); for(x = 0;x < 4;x++)//發原密碼 { DATA = *(p++); for(i = 0;i < 8;i++) { write_bit(BIT0); DATA >>= 1; } } write_bit(0);//鎖定位0:0 p = &cominceptbuff[0]; write_block(0x00,p);//寫新配置參數:pwd=0 //密碼無效:即清除密碼 DATA = 0x00;//停止操作碼00000000B for(i = 0;i < 2;i++) { write_bit(BIT7); DATA <<= 1; } p_U2270B_CFE = 1; delay_2(560);//5.6ms } /*********************************/ void f_changepassword()//修改密碼 { uchar data *data p; uchar i,x,addr; addr = 0x07;//block7 p = &Nkey_a[0];//原密碼 DATA = 0x80;//操作碼10:10xxxxxxB for(i = 0;i < 2;i++) { write_bit(BIT7); DATA <<= 1; } for(x = 0;x < 4;x++)//發原密碼 { DATA = *(p++); for(i = 0;i < 8;i++) { write_bit(BIT7); DATA >>= 1; } } write_bit(0);//鎖定位0:0 p = &cominceptbuff[0]; write_block(0x07,p);//寫新密碼 p_U2270B_CFE = 1; bankdata[24] = cominceptbuff[0];//密碼存入 bankdata[25] = cominceptbuff[1]; bankdata[26] = cominceptbuff[2]; bankdata[27] = cominceptbuff[3]; DATA = 0x00;//停止操作碼00000000B for(i = 0;i < 2;i++) { write_bit(BIT7); DATA <<= 1; } p_U2270B_CFE = 1; delay_2(560);//5.6ms } /***************************子函數***********************************/ void write_bit(bit x)//寫一位 { if(x) { p_U2270B_CFE = 1; delay_2(32);//448*11.0592/120=42延時448us p_U2270B_CFE = 0; delay_2(28);//280*11.0592/120=26寫1 } else { p_U2270B_CFE = 1; delay_2(92);//192*11.0592/120=18 p_U2270B_CFE = 0; delay_2(28);//280*11.0592/120=26寫0 } } /*******************寫一個block*******************/ void write_block(uchar addr,uchar data *data p) { uchar i,j; for(i = 0;i < 4;i++)//block0數據 { DATA = *(p++); for(j = 0;j < 8;j++) { write_bit(BIT0); DATA >>= 1; } } DATA = addr <<= 5;//0地址 for(i = 0;i < 3;i++) { write_bit(BIT7); DATA <<= 1; } } /*************************************************/ void write_password(uchar data *data p) { uchar i,j; for(i = 0;i < 4;i++)// { DATA = *(p++); for(j = 0;j < 8;j++) { write_bit(BIT0); DATA >>= 1; } } } /*************************************************/ void main() { initial(); TI = RI = 0; ES = 1; EA = 1; delay_2(28); //f_readcard(); while(1) { f_readcard(); //讀卡 f_writecard(command1); //寫卡 f_clearpassword(); //清除密碼 f_changepassword(); //修改密碼 } }
標簽: 12345
上傳時間: 2017-10-20
上傳用戶:my_lcs