{"id":2782,"date":"2018-05-06T09:39:28","date_gmt":"2018-05-06T00:39:28","guid":{"rendered":"http:\/\/otsuka.biz\/blog1\/?p=2782"},"modified":"2024-02-12T17:28:14","modified_gmt":"2024-02-12T08:28:14","slug":"ntp-client-as-a-simple-clock-using-pic18f27j53-and","status":"publish","type":"post","link":"https:\/\/otsuka.biz\/blog1\/ntp-client-as-a-simple-clock-using-pic18f27j53-and\/","title":{"rendered":"NTP client as a simple clock using PIC18F27J53 and MRF24WG0MA"},"content":{"rendered":"<p>&lt;&lt; Introduction in Japanese &gt;&gt;<\/p>\n<p>\u9023\u4f11\u306e\u6700\u5f8c\u306b\u3001Wi-Fi \u30e2\u30b8\u30e5\u30fc\u30eb MRF24WG0MA \u3092\u63a5\u7d9a\u3057\u305f\u5b9f\u9a13\u30dc\u30fc\u30c9\u306e\u52d5\u4f5c\u78ba\u8a8d\u3068\u3057\u3066 NTP client \u3068\u3057\u3066\u306e\u5b9f\u9a13\u3092\u884c\u3063\u305f\u3002\u3059\u306a\u308f\u3061\u30012017\u5e747\u670814\u65e5\u306e\u7a3f\uff08NTP client as a simple clock using PIC18F27J53 and ENC28J60\uff09\u3067\u8a18\u3057\u305f\u3001\u60c5\u5831\u901a\u4fe1\u7814\u7a76\u6a5f\u69cb ntp.nict.jp \u306e\u00a0NTP server \u306b\u63a5\u7d9a\u3057\u3066\u3001\u73fe\u5728\u6642\u523b\u3092\u53d6\u5f97\u3059\u308b\u5b9f\u9a13\u306e\u518d\u73fe\u3067\u3042\u308b\u3002<\/p>\n<p>\u5b9f\u9a13\u306b\u5408\u308f\u305b\u3066\u3001MainDemo.c\u3001TCPIP MRF24W.h\u3001BerkeleyUDPClientDemo.c\u00a0\u3092\u5909\u66f4\u3057\u305f\u3002<\/p>\n<p>\u66f4\u306b\u00a0NTP server \u304b\u3089\u306e\u53d7\u4fe1\u30c7\u30fc\u30bf\u3092\u57fa\u6e96\u306b\u3001CCP \u3068 Timer1 \u306b\u3088\u308a1\u79d2\u5272\u8fbc\u3092\u767a\u751f\u3055\u305b\u3066\u6642\u523b\u66f4\u65b0\u3057\u3001\u5353\u4e0a\u6642\u8a08\u3068\u3057\u3066\u6a5f\u80fd\u3055\u305b\u3066\u3044\u308b\u3002\u3053\u3053\u3067\u3001CCP \u3092\u9ad8\u4f4d\u5272\u308a\u8fbc\u307f\u3067\u5229\u7528\u3057\u3066\u3001MRF24WG0MA \u304b\u3089\u306e\u4fe1\u53f7\u306f\u4f4e\u4f4d\u5272\u308a\u8fbc\u307f\u3067\u51e6\u7406\u3055\u305b\u3066\u3044\u308b\u3002<\/p>\n<p><a href=\"http:\/\/otsuka.biz\/blog1\/wp-content\/uploads\/2018\/05\/NTP-client-with-MRF24WG.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2794\" src=\"http:\/\/otsuka.biz\/blog1\/wp-content\/uploads\/2018\/05\/NTP-client-with-MRF24WG.jpg\" alt=\"\" width=\"2497\" height=\"2405\" srcset=\"https:\/\/otsuka.biz\/blog1\/wp-content\/uploads\/2018\/05\/NTP-client-with-MRF24WG.jpg 2497w, https:\/\/otsuka.biz\/blog1\/wp-content\/uploads\/2018\/05\/NTP-client-with-MRF24WG-300x289.jpg 300w, https:\/\/otsuka.biz\/blog1\/wp-content\/uploads\/2018\/05\/NTP-client-with-MRF24WG-768x740.jpg 768w, https:\/\/otsuka.biz\/blog1\/wp-content\/uploads\/2018\/05\/NTP-client-with-MRF24WG-1024x986.jpg 1024w\" sizes=\"auto, (max-width: 2497px) 100vw, 2497px\" \/><\/a><\/p>\n<p>The &#8220;BerkeleyUDPClientDemo.c&#8221; in the\u00a0TCP\/IP stack of Microchip Libraries for Applications v2013-06-15 is\u00a0at work on\u00a0my board.<\/p>\n<p>The\u00a0Wi-Fi board was reported in my page on\u00a0May 4, 2018.<\/p>\n<p><a href=\"https:\/\/www.nict.go.jp\/en\/\">The NTP server of National Institute of Information and Communications Technology<\/a> is used in this project and Coordinated Universal Time (UTC) is converted to Japan Standard Time (JST: UTC + 9 hours).<\/p>\n<p><span class=\"KejjeYrKwrd\">Furthermore<\/span>, this test board works as a simple clock.\u00a0 An interruption of every one second in high priority is generated by the CCP1 module, which increments the timestamp obtained from the NTP server.\u00a0 So the external interrupt by the MRF24WG0MA module has been set in low priority.<\/p>\n<p>&lt;&lt; Sample code\u00a0of\u00a0the NTP client\u00a0&gt;&gt;<\/p>\n<div class='w3eden'><!-- WPDM Link Template: Default Template -->\n\n<div class=\"link-template-default card mb-2\">\n    <div class=\"card-body\">\n        <div class=\"media\">\n            <div class=\"mr-3 img-48\"><img decoding=\"async\" class=\"wpdm_icon\" alt=\"\u30a2\u30a4\u30b3\u30f3\" src=\"data:image\/svg+xml;base64,CiAgICAgICAgICAgIDxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2aWV3Qm94PSIwIDAgNDAgNDAiPgogICAgICAgICAgICAgICAgPGRlZnM+CiAgICAgICAgICAgICAgICAgICAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkaWVudCIgeDE9IjAiIHkxPSIwIiB4Mj0iMCIgeTI9IjEiPgogICAgICAgICAgICAgICAgICAgICAgICA8c3RvcCBzdG9wLWNvbG9yPSIjMjY5ZGVmIiBvZmZzZXQ9IjAiLz4KICAgICAgICAgICAgICAgICAgICAgICAgPHN0b3Agc3RvcC1jb2xvcj0iIzI2YmRlZiIgb2Zmc2V0PSIxIi8+CiAgICAgICAgICAgICAgICAgICAgPC9saW5lYXJHcmFkaWVudD4KICAgICAgICAgICAgICAgIDwvZGVmcz4KICAgICAgICAgICAgICAgIDxnPgogICAgICAgICAgICAgICAgICAgIDxyZWN0IGZpbGw9InVybCgjZ3JhZGllbnQpIiB4PSIwIiB5PSIwIiB3aWR0aD0iNDAiIGhlaWdodD0iNDAiIHJ4PSIzIiByeT0iMyIvPgogICAgICAgICAgICAgICAgICAgIDx0ZXh0IHg9IjUiIHk9IjE5IiBmb250LWZhbWlseT0iQXJpYWwsIEhlbHZldGljYSwgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIxM3B4IiBsZXR0ZXItc3BhY2luZz0iMSIgZmlsbD0iI0ZGRkZGRiI+CiAgICAgICAgICAgICAgICAgICAgICAgIDx0c3Bhbj5MWkg8L3RzcGFuPgogICAgICAgICAgICAgICAgICAgICAgICA8dHNwYW4geD0iNiIgeT0iMjgiPl88L3RzcGFuPgogICAgICAgICAgICAgICAgICAgIDwvdGV4dD4KICAgICAgICAgICAgICAgIDwvZz4KICAgICAgICAgICAgPC9zdmc+CgoJCQk=\" \/><\/div>\n            <div class=\"media-body\">\n                <h3 class=\"package-title\"><a href='https:\/\/otsuka.biz\/blog1\/download\/ntp_mrf24wg\/'>NTP_MRF24WG<\/a><\/h3>\n                <div class=\"text-muted text-small\"><i class=\"fas fa-copy\"><\/i> 1 \u30d5\u30a1\u30a4\u30eb <i class=\"fas fa-hdd ml-3\"><\/i> 1.35 MB<\/div>\n            <\/div>\n            <div class=\"ml-3\">\n                <a class='wpdm-download-link download-on-click btn btn-primary ' rel='nofollow' href='#' data-downloadurl=\"https:\/\/otsuka.biz\/blog1\/download\/ntp_mrf24wg\/?wpdmdl=3400&refresh=69de20c8af2b61776165064\">\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/a>\n            <\/div>\n        <\/div>\n    <\/div>\n<\/div>\n\n<\/div>\n<p>(Compiled by\u00a0the C18 under\u00a0the large code model)<\/p>\n<p>In TCPIPConfig.h, the default network configuration must be adjusted to your local network (MAC address, IP\u00a0address and so on).\u00a0 In addition, STACK_USE_ICMP_SERVER, STACK_USE_DNS and STACK_USE_BERKELEY_API\u00a0are defined so that the Ethernet board\u00a0can work as a NTP client using the Berkeley Socket.<\/p>\n<p>In WF_Config.h, the parameters must be adjusted to your Wi-Fi network.<\/p>\n<p>&lt;&lt; Operation of the NTP client &gt;&gt;<\/p>\n<p>Initialization:\u00a0\u00a0\u00a0 If the Ethernet board is connected to the Internet for the first time, the current time can be automatically obtained from the NTP server.<\/p>\n<p>Adjustment of the time:\u00a0\u00a0\u00a0 Every time the RB3 pin (BUTTON 0) is pulled down, the current time will be gotten from the NTP server.<\/p>\n<p>\u4f7f\u7528\u65b9\u6cd5\uff1a\u3000TCPIPConfig.h \u30d5\u30a1\u30a4\u30eb\u306b\u30ed\u30fc\u30ab\u30eb\u30fb\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u60c5\u5831\u3092\u8a2d\u5b9a\u3002\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u306b\u63a5\u7d9a\u3059\u308b\u3068\u3001\u521d\u56de\u306e\u6642\u523b\u8a2d\u5b9a\u306f\u81ea\u52d5\u7684\u306b NTP \u30b5\u30fc\u30d0\u30fc\u306b\u63a5\u7d9a\u3055\u308c\u3066\u6642\u9593\u3092\u523b\u307f\u59cb\u3081\u308b\u3002\uff12\u56de\u76ee\u4ee5\u964d\u306e\u6642\u523b\u88dc\u6b63\u306b\u306f\u3001\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u63a5\u7d9a\u3055\u308c\u305f\u72b6\u614b\u3067\u30b9\u30a4\u30c3\u30c1 (RB3) \u3092\u62bc\u3059\u3068 NTP \u30b5\u30fc\u30d0\u30fc\u306b\u63a5\u7d9a\u3055\u308c\u3066\u73fe\u5728\u6642\u523b\u306b\u66f4\u65b0\u3055\u308c\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;&lt; Introduction in Japanese &gt;&gt; \u9023\u4f11\u306e\u6700\u5f8c\u306b\u3001Wi-Fi \u30e2\u30b8\u30e5\u30fc\u30eb MRF24WG0MA \u3092\u63a5\u7d9a\u3057\u305f\u5b9f\u9a13\u30dc\u30fc\u30c9\u306e\u52d5\u4f5c\u78ba\u8a8d\u3068\u3057\u3066 NTP client \u3068\u3057\u3066\u306e\u5b9f\u9a13\u3092 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"vkexunit_cta_each_option":"","footnotes":""},"categories":[2,12,5],"tags":[],"class_list":["post-2782","post","type-post","status-publish","format-standard","hentry","category-pic","category-internet","category-radio-frequency"],"_links":{"self":[{"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/posts\/2782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/comments?post=2782"}],"version-history":[{"count":2,"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/posts\/2782\/revisions"}],"predecessor-version":[{"id":3401,"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/posts\/2782\/revisions\/3401"}],"wp:attachment":[{"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/media?parent=2782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/categories?post=2782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/tags?post=2782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}