
mbed/ARM 活用事例 第2章 キャラクタLCDを極めよう
main.cpp@0:8f82c02ccf5d, 2011-10-04 (annotated)
- Committer:
- sunifu
- Date:
- Tue Oct 04 12:50:27 2011 +0000
- Revision:
- 0:8f82c02ccf5d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sunifu | 0:8f82c02ccf5d | 1 | #include "mbed.h" |
sunifu | 0:8f82c02ccf5d | 2 | #include "TextLCD.h" |
sunifu | 0:8f82c02ccf5d | 3 | |
sunifu | 0:8f82c02ccf5d | 4 | void slideMessage(char* ,double ,int ); |
sunifu | 0:8f82c02ccf5d | 5 | //slideMessage(message, slidetime, row ) |
sunifu | 0:8f82c02ccf5d | 6 | |
sunifu | 0:8f82c02ccf5d | 7 | TextLCD lcd(p24,p26,p27,p28,p29,p30); |
sunifu | 0:8f82c02ccf5d | 8 | #define SIZE 16 |
sunifu | 0:8f82c02ccf5d | 9 | // I don't test TextLCD 20x ... 16x2B |
sunifu | 0:8f82c02ccf5d | 10 | |
sunifu | 0:8f82c02ccf5d | 11 | int main() { |
sunifu | 0:8f82c02ccf5d | 12 | static char msg[] = "1234567890123456" ; |
sunifu | 0:8f82c02ccf5d | 13 | static char msg1[] = "Welcome to mbed! mbed is a tool for Rapid Prototyping with Microcontrollers." ; |
sunifu | 0:8f82c02ccf5d | 14 | static char msg2[] = "abcdefghijklmnop" ; |
sunifu | 0:8f82c02ccf5d | 15 | |
sunifu | 0:8f82c02ccf5d | 16 | slideMessage(msg1,0.5,0); |
sunifu | 0:8f82c02ccf5d | 17 | return 0 ; |
sunifu | 0:8f82c02ccf5d | 18 | } |
sunifu | 0:8f82c02ccf5d | 19 | |
sunifu | 0:8f82c02ccf5d | 20 | void slideMessage(char msg[], double time,int row) |
sunifu | 0:8f82c02ccf5d | 21 | { |
sunifu | 0:8f82c02ccf5d | 22 | int j, k ; |
sunifu | 0:8f82c02ccf5d | 23 | int len = ( strlen(msg) ) ; |
sunifu | 0:8f82c02ccf5d | 24 | |
sunifu | 0:8f82c02ccf5d | 25 | lcd.cls(); |
sunifu | 0:8f82c02ccf5d | 26 | |
sunifu | 0:8f82c02ccf5d | 27 | while(1){ // <= Debug ha while wo comment nisuru |
sunifu | 0:8f82c02ccf5d | 28 | printf("[len:%d :: %s]",len,msg); // <= Debug |
sunifu | 0:8f82c02ccf5d | 29 | printf("----- first loop -----\r\n"); // <= Debug |
sunifu | 0:8f82c02ccf5d | 30 | for (j = SIZE -1 ; j>=0 ; j-- ){ |
sunifu | 0:8f82c02ccf5d | 31 | printf("(%2d)",j); // <= Debug |
sunifu | 0:8f82c02ccf5d | 32 | for ( k = j ; k < SIZE ; k++ ){ |
sunifu | 0:8f82c02ccf5d | 33 | lcd.locate(k,row); |
sunifu | 0:8f82c02ccf5d | 34 | if ( len > (k - j) ){ |
sunifu | 0:8f82c02ccf5d | 35 | lcd.printf("%c",msg[k-j]) ; |
sunifu | 0:8f82c02ccf5d | 36 | printf("[%2d:%c]",k,msg[k-j]); // <= Debug |
sunifu | 0:8f82c02ccf5d | 37 | }else{ |
sunifu | 0:8f82c02ccf5d | 38 | lcd.printf(" ") ; |
sunifu | 0:8f82c02ccf5d | 39 | printf("[%2d:*]",k); // <= Debug |
sunifu | 0:8f82c02ccf5d | 40 | } |
sunifu | 0:8f82c02ccf5d | 41 | } |
sunifu | 0:8f82c02ccf5d | 42 | wait(time) ; |
sunifu | 0:8f82c02ccf5d | 43 | printf("\r\n"); // <= Debug |
sunifu | 0:8f82c02ccf5d | 44 | } |
sunifu | 0:8f82c02ccf5d | 45 | printf("----- second loop -----\r\n"); // <= Debug |
sunifu | 0:8f82c02ccf5d | 46 | for ( j = 1 ; j <= len ; j++ ){ |
sunifu | 0:8f82c02ccf5d | 47 | printf("(%2d)",j); // <= Debug |
sunifu | 0:8f82c02ccf5d | 48 | for ( k = 0; k < SIZE ; k++ ){ |
sunifu | 0:8f82c02ccf5d | 49 | lcd.locate(k,row) ; |
sunifu | 0:8f82c02ccf5d | 50 | if( ( k + j ) < len ){ |
sunifu | 0:8f82c02ccf5d | 51 | lcd.printf("%c",msg[k+j]) ; |
sunifu | 0:8f82c02ccf5d | 52 | printf("[%2d:%c]",k,msg[k+j]); // <= Debug |
sunifu | 0:8f82c02ccf5d | 53 | }else{ |
sunifu | 0:8f82c02ccf5d | 54 | lcd.printf(" ") ; |
sunifu | 0:8f82c02ccf5d | 55 | printf("[%2d:*]",k); // <= Debug |
sunifu | 0:8f82c02ccf5d | 56 | } |
sunifu | 0:8f82c02ccf5d | 57 | } |
sunifu | 0:8f82c02ccf5d | 58 | wait(time) ; |
sunifu | 0:8f82c02ccf5d | 59 | printf("\r\n"); // <= Debug |
sunifu | 0:8f82c02ccf5d | 60 | } |
sunifu | 0:8f82c02ccf5d | 61 | } // <= Debug ha kokomo comment ni suru. |
sunifu | 0:8f82c02ccf5d | 62 | } |